Possible Duplicate:
Convert char array to single int?
I have
char[] str = "124"
I want to get a single int i
with i==124
.
Which function do I have to use?
Possible Duplicate:
Convert char array to single int?
I have
char[] str = "124"
I want to get a single int i
with i==124
.
Which function do I have to use?
Try atoi() from the C standard library:
#include <cstdlib>
char str[] = "124";
int i = atoi(str);
Or, possibly better, use strtol():
#include <cstdlib>
char str[] = "124";
int i = strtol(str, NULL, 0);
Create a stringstream from the char-Array and use << for conversion to int.