| Amnesiac (49) | |||||
|
My program is supposed to: Prompt user to enter a sentence Read this sentence into a string Pass the string to a function that separates each word Each word then becomes an element in a vector<string> The program runs but there is just blank output when I want to write the vector's elements to the screen. This is the separating function
and the simple main()
Any ideas? | |||||
|
|
|||||
| coder777 (2550) | |
1. this cin >> s; stores only the first word (i.e. until but not including the first space -> use getline())http://www.cplusplus.com/reference/string/getline/ 2. make_sentence() does not store anything in the vector if there's no space
| |
|
|
|
| Amnesiac (49) | |
| Why does make_sentence() not store anything in the vector? Usually you can declare an empty vector and still use push_back() to add elements to it, what am I doing differently? | |
|
|
|
| MiiNiPaa (232) | |
| 3. you aren't pushing back last word in line. | |
|
|
|
| coder777 (2550) | |
|
on line 10: There's a space required to store the word. No space no word stored. after the loop: check if test is not empty. If so store it in the vector.
| |
|
|
|