Two ways to convert C++ string to integer

Hits: 0

example:

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

example:

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

You may also like...

Leave a Reply

Your email address will not be published.