Hello wonderful people of the internet!
here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
#include "../../std_lib_facilities.h"
int main () {
string previous = " ";
string current;
while (cin >> current) {
if (previous == current) {
cout << "repeated word: " << current << '\n';
previous = current;
}
}
return 0;
}
|
(this is an example in the Bjarne book). I've read over the explanation multiple times, but I still cannot understand.
What does string previous = " "; do?
It initializes previous to the character space (like when you press space). But I thought in CPP it doesn't read it, something about the compiler skipping over whitespace. Why initialize it to that then?
Another thing, I didn't tell the program to ask me for an input. I realize I have
while (cin >> current)
but I didn't have a line before saying something like "Please enter input" then next line:
cin >> input; or cin >> current
Without having the above, it still expects an input, but why is this?
Finally, in the book it says do try this: Use the input "The cat cat jumped". Ok, I get it the program should probably return to me cat twice, but it doesn't do that. Even the next 'try this' is telling me to input
She she laughed He He...etc he did did not.. etc.
I realize it wants me to learn that 'She' and 'she' are not the same. But when I enter these inputs, the program doesn't do anything. It only remains in an ongoing state of expecting an input. What's the deal with that?
Thank you very much for your help
-ilovejapanesegirls