Noob here, I've writing the examples from Stroustrup's book "Programming: Principles and Practice Using C++" to my compiler just to practise and try the examples provided, so far so good until now that I can't get anything off of this piece of code, and I can't figure it out, once compiled I just can write endless words without any result. Am I doing anything wrong? Is it supposed to be like this? could it be the compiler? I want to return the results "Number of words" and cout << words[i] << '\n\; but it doesn't do anything.
I'm using:
Microsoft Visual Studio Community 2015
Version 14.0.25431.01 Update 3
this is the code verbatim from the book chapter 4.6.4:
#include "std_lib_facilities.h"
// simple dictionary: listed 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";
return 0;
}