type casting
cout << (int)x;
laconstantine
Junior Poster in Training
70 posts since May 2007
Reputation Points: 10
Solved Threads: 1
type casting
cout << (int)x;
Yeah, right. :icon_rolleyes:
#include <iostream>
using namespace std;
int main() {
char myString[] = "1234567890";
cout << (int)myString << endl;
return 0;
}
/* output
# ./a.out
-1073743883
#
*/
Since you're in C++, I'd recommend stringstreams:
istringstream iss(myString);
int num;
iss >> num;
Don't forget to include <sstream> .
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
The way you are doing it works well, especially if there are more numbers in the array.
And we'd rather have a long title that tells us the topic of the post rather than the usual "help me" or "What's wrong with this urgent" junk titles. So thank you for your long title. :icon_mrgreen:
WaltP
Posting Sage w/ dash of thyme
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944