In the C++ book Programming: Principles and Practice Using C++, there's an example code like this for detecting repeated words:

Code:
#include "std_lib_facilities.h"

int main()
{
    int number_of_words = 0;
    string previous = " ";       // previous word; initialized to “not a word”
    string current;                             // current word
    while (cin >> current)        // read a stream of words
    {
        if (previous == current)    // check if the word is the same as last
        {
            ++number_of_words;
            cout << "word number " << number_of_words << " repeated: " << current << "\n";
            previous = current;
        }
    }
    keep_window_open();
}
The header file in there is sort of like a set of training-wheels for students who are complete beginners to the language; the function keep_window_open() is defined in there and it does just that on Windows systems where the output window closes too fast (in the case of the function, it's just like cin.ignore(), except it waits for you enter a character, like 'j', before it exits); programs on my Windows laptop work fine on Code::Blocks, but when I create a .exe file for them and double-click that file, it does actually close too quickly for me to be able to see the output (if it's a program like the generic "Hello World!" program that just outputs text to the screen and then exits - so all I see is the output window just flash-by really fast in those cases).

Anyway, as for the problem I'm having with the code: there are no error and compile- or link-time, but it does behave strangely at runtime, where the part inside the curly-braces of the while-loop doesn't execute at all. So I'm wondering where the problem is.