Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

C++ n00b question

Name: Anonymous 2011-09-20 10:08

I don´t understand the following code, particularly how the next string is stored into "previous". "cin>>current" just moves words into current. Where is the order to move the next word into previous? Code is from Stroustup:

[code]
int main()
{
   string previous = " ";
   string current;
   while (cin>>current){
      if(previous==current)
         cout<<"word repetition:"<<current<<'\n';
      previous=current;
   }
}

Name: Anonymous 2011-09-20 11:37

[/code]

Name: Anonymous 2011-09-20 15:44

previous=current;

Don't change these.
Name: Email:
Entire Thread Thread List