Two ways to convert C++ string to integer

Hits: 0


string str=“123”;

int a=atoi(str.c_str());

int b=stoi(str);

You can use atoi or stoi , atoi is more efficient.

If it is a long shape, you can use stoll


string num="719387492312";
long long res=stoll(num);

You may also like...

Leave a Reply

Your email address will not be published.