// Code derived from Stroustrup's PPP2 book// § 3.5.1 An example: detect repeated words// -beginning on p 71#include<iostream>#include<string>usingstd::cin;usingstd::cout;usingstd::string;intmain(){cout<<"Please enter words (use ctrl+d to end input)\n";stringprevious=" ";// previous word; initialized to “not a word”stringcurrent;// current wordwhile(cin>>current){// read a stream of wordsif(previous==current)// check if the word is the same as lastcout<<"repeated word: "<<current<<'\n';previous=current;}}