Skip to content

Instantly share code, notes, and snippets.

@robnolen
Created January 31, 2012 06:48
Show Gist options
  • Save robnolen/1709282 to your computer and use it in GitHub Desktop.
Save robnolen/1709282 to your computer and use it in GitHub Desktop.
Stringstream example
#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