home
search
help
profile
liking the experience? our app is even better
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now  
showing results for input string stream
1#include <iostream>
2#include <vector>
3#include <string>
4#include <sstream>
5using namespace std;
6int main() {
7   string str("Hello from the dark side");
8   string tmp; // A string to store the word on each iteration.
9   stringstream str_strm(str);
10   vector<string> words; // Create vector to hold our words
11   while (str_strm >> tmp) {
12      // Provide proper checks here for tmp like if empty
13      // Also strip down symbols like !, ., ?, etc.
14      // Finally push it.
15      words.push_back(tmp);
16   }
17   for(int i = 0; i<words.size(); i++)
18      cout << words[i] << endl;
19}
upvote
downvote
source