I'm beginner to Cpp and trying to go through the examples given a book named "Programming Principles and Practice using c++" (2nd edition).
For further reference I'm talking about the "4.6.4 A text example" where a sentence needs to be taken as an input and build a dictionary of words (after sorting).
The example which was mentioned was like the below.
// simple dictionary: list of sorted words
int main()
{
vector<string> words;
for(string temp; cin>>temp; ) // read whitespace-separated words
words.push_back(temp); // put into vector
cout << "Number of words: " << words.size() << '\n';
sort(words); // sort the words
for (int i = 0; i<words.size(); ++i)
if (i==0 || words[i–1]!=words[i]) // is this a new word?
cout << words[i] << "\n";
}
In the above code sample line number 5 (in the for loop expression), the cin >> temp didn't make sense to me. Why? After running the code the console popped up and I started to enter the sentence with couple of words and even after hitting enter, I wasn't able to terminate the string and go to the next line? How to terminate inputs here?