Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can I convert a string into a int?

Status
Not open for further replies.

hoggle

Programmer
Jul 13, 2001
124
0
0
US
I want to turn my string into an int.
also the string will always contain a valid integer.

thanks
 
use the [tt]atoi()[/tt] and [tt]atol()[/tt] functions:

[tt]
char str[100] = "12345";

int i = atoi(str);

// i now equals 12345
[/tt]
tellis.gif

[sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]​
 
if you are using the String class (not a character array) you need to use the following:

Code:
String str = "12345";
int i = atoi(str.c_str());
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top