I'm new here and excited to share ideas and learn from one another.
I'm going through Stroustrup's book "Programming." I'm doing this on my own, so I am going to need all the help I can get. I appreciate your patience ahead of time. Maybe someday I'll be able to help people just like me on this forum in later days.
I'm compiling with Dev-C++. Also, I am using a specific header file as you can see in the #include.
Anyway, here is the code:
1 2 3 4 5 6 7 8 9 10 11 12
#include "std_lib_facilities.h"
int main()
{
string previous = " "; // previous word initialized to "not a word"
string current; // current word
while (cin>>current){ // read stream of words
if (previous == current); // check if word is same as the last
cout<<"repeated word: "<<current<<'\n';
previous = current;
}
}
Instead of returning repeated words, all words are being returned after the string. Frustrating.