Jan 25, 2003 #1 hoggle Programmer Joined Jul 13, 2001 Messages 124 Location US I want to turn my string into an int. also the string will always contain a valid integer. thanks
Jan 25, 2003 #2 qednick Programmer Joined Jul 26, 2002 Messages 516 Location US use the [tt]atoi()[/tt] and [tt]atol()[/tt] functions: [tt] char str[100] = "12345"; int i = atoi(str); // i now equals 12345 [/tt] programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek. Upvote 0 Downvote
use the [tt]atoi()[/tt] and [tt]atol()[/tt] functions: [tt] char str[100] = "12345"; int i = atoi(str); // i now equals 12345 [/tt] programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.
Jan 26, 2003 #3 Zejjeu592 Programmer Joined Jul 27, 2001 Messages 22 Location US 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()); Upvote 0 Downvote
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());