๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’Ž/C++

[C++] int to string, string to int | to_string, stoi

by dar0m! 2020. 3. 10.

โ— int → string

#<string>

to_string

int num = 12345;

string str = to_string(num);

โ— string → int

#<string>

stoi

string str = "abcde";

int num = stoi(str);

โ— char* → int

#<stdilb.h> ๋˜๋Š” #<cstdlib>

atoi()

char* cStr = "abcde";

int num = atoi(cStr);

โ— string → char* → int

#<cstdlib>, #<string>

                 c_str()  →  atoi()

string s = "abcde";

int num = atoi(s.c_str());

๋Œ“๊ธ€