Created
September 24, 2012 15:22
-
-
Save timdrichards/3776507 to your computer and use it in GitHub Desktop.
Convert string to int
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <iostream> | |
#include <sstream> | |
using namespace std; | |
int main() { | |
// This is how you would convert a C++ string into an integer: | |
string str1 = "45"; | |
stringstream sstr1(str1); | |
int x; | |
sstr1 >> x; | |
cout << "The x integer: " << x << endl; | |
char* str2 = "46"; | |
stringstream sstr2(str2); | |
sstr2 >> x; | |
cout << "The x integer: " << x << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment