1. atoi(), stoi()
int main(){
string a = "-1234";
cout << atoi(a.c_str()) << '\n';
cout << stoi(a);
}
[출력]
-1234
-1234
stoi()뿐만아니라 stod(), stol(), stof() 도 존재한다.
2. to_string()
int main(){
int a = -1234;
cout << to_string(a);
}
[출력]
"-1234"
'C++' 카테고리의 다른 글
[C++] 뒤집는 함수 : reverse() (0) | 2024.03.01 |
---|---|
[C++] stack, queue, deque 관련 함수 (0) | 2024.02.15 |
[C++] list 관련 함수 정리 : push_front(), insert(), erase(), pop_front(), front(), clear(), ... (0) | 2024.02.15 |
[C++] lower_bound()와 upper_bound() (0) | 2024.02.14 |
[C++] string 관련 함수 : insert(), erase(), find(), substr(), split(), ... (0) | 2024.02.13 |