- atoi, atol, atoll : null 종료 문자열을 정수로 바꾼다.
- stoul, stoull : 문자열을 부호 없는 정수로 바꾼다.
- stof, stod, stold : 문자열을 부동 소수점 값으로 바꾼다.
- to_string : 정수나 부동 소수점 값을 문자열로 바꾼다.
atoi 로 문자를 정수로 변경 시 숫자가 아닌 값은 오류를 발생 한다.
오류 없이 정수만 변환하며 문자는 아무 값 없이 변환 되어 넘어 가는 예외 처리가 필요한 경우
stoi, stol 이나 stoll 을 사용 하자.
//!< string / wstring : 변환 문자열
//!< pos : 변환 중 문자 로드한 위치 (null 이면 미반환)
//!< base : 정수 진법 (EX : 16 진법 시 문자 앞 0x 설정 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F 로드)
int stoi(const std::string& str, std::size_t* pos = 0, int base = 10);
int stoi(const std::wstring& str, std::size_t* pos = 0, int base = 10);
long stol(const std::string& str, std::size_t* pos = 0, int base = 10);
long stol(const std::wstring& str, std::size_t* pos = 0, int base = 10);
long long stoll(const std::string& str, std::size_t* pos = 0, int base = 10);
long long stoll(const std::wstring& str, std::size_t* pos = 0, int base = 10);
출처 : C++ 레퍼런스 - string 의 stoi, stol, stoll 함수
C++ 레퍼런스 - string 의 stoi, stol, stoll 함수
모두의 코드 C++ 레퍼런스 - string 의 stoi, stol, stoll 함수 작성일 : 2019-09-19 이 글은 20170 번 읽혔습니다. string 혹은 wstring 문자열 str 을 base 진법을 사용하는 부호 있는 정수로 변환한 값을 리턴한다.
modoocode.com
'[ Programing ] > STL & Booster' 카테고리의 다른 글
C++ 문자열로 to_string (0) | 2025.02.11 |
---|---|
boost::thread_group (0) | 2023.06.26 |
C++ STL mutex (0) | 2022.01.21 |
C++ STL fill_n / fill (0) | 2021.01.22 |
C++ STL Function (0) | 2020.09.14 |