Created
January 31, 2012 06:48
-
-
Save robnolen/1709282 to your computer and use it in GitHub Desktop.
Stringstream example
This file contains hidden or 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 <iostream> | |
#include <sstream> | |
#include <string> | |
using namespace std; | |
int main() { | |
string line; | |
string temp; | |
stringstream stream; //our stringstream | |
while (line != "done") { //grab input until done. | |
getline(cin, line); //cin.getline only works with char. this works with string. | |
stream << line; //extract line into stream | |
while (stream >> temp) { | |
cout << "Element of stream: " << temp << endl; | |
} | |
stream.clear(); //important, or stream won't reset with each new line | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment