Jan 25, 2003 #1 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
Jan 25, 2003 #2 qednick Programmer Jul 26, 2002 516 0 0 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] [sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup] 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] [sup]programmer (prog'ram'er), n A hot-headed, anorak wearing, pimple-faced computer geek.[/sup]
Jan 26, 2003 #3 Zejjeu592 Programmer Jul 27, 2001 22 0 0 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());