Please tell me the functions for converting string type to integer in C++
Here is an example, actually you need to drive a number from S into N
# include & lt; string & gt;
int main ()
{
string S = "74";
int N;
return 0;
}
Answer 1, authority 100%
# include & lt; stdlib.h & gt;
n = atoi (S.c_str ());
Answer 2, authority 75%
# include & lt; iostream & gt;
#include & lt; sstream & gt;
#include & lt; string & gt;
using namespace std;
int main () {
string S = "74";
istringstream iss (S, istringstream :: in);
int val;
iss & gt; & gt; val;
return 0;
}
Answer 3, authority 50%
# include & lt; iostream & gt;
#include & lt; string & gt;
using namespace std;
void main () {
string str = "1234567890";
int num = NULL;
for (int i = 0; i & lt; str.length (); i ++) {
num = num * 10 + str [i] - 0x30;
}
cout & lt; & lt; num;
}