I need your precious help for a little question! I am reading a Bjarne Stroustrup book and I found this example:
int main()
{
   string previous = " ";
   string current;
   while (cin >> current) {                                    
      if(previous == current)
        cout << "repeated word: " << current << '\n';
      previous = current;
   }                                                            
   return 0;
}
My question is: what does the line previous = "" do; make?
Initializes the previous character space (for example, by pressing the spacebar). But I thought that in C ++ he does not read it, something about the compiler, skipping spaces. Why initialize it before that?
I tried to write like this: string previous; , and the program still works correctly ... right? What is differnece? Please enlighten me x)
source
share