Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <stdio.h>
- #include <stdlib.h>
- using namespace std;
- int main(int argc, const char * argv[])
- {
- string sentence;
- string tmp;
- vector<string> v;
- cout << "Enter a sentence: ";
- getline(cin, sentence);
- for(int i = 0; i < sentence.length(); i++) {
- tmp += sentence[i];
- // Check for whitespace or if we are at the end of the string
- if((sentence[i] == ' ') || (i == sentence.length() - 1)) {
- // push back current tmp value
- v.push_back(tmp);
- // clear tmp string
- tmp = "";
- }
- }
- for (int i = 0; i < v.size(); i++)
- {
- cout << v[i] << " ";
- }
- cout << endl;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement