Going through a text to help cement my knowledge of C++ but found code that wasn't explained and looks kinda odd to me.
#include <iostream>
#include <string>
int main()
{
using namespace std;
char ch;
int count = 0;
cin.get(ch);
while(ch != '\n')
{
cout << ch;
++count;
cin.get(ch);
}
cout << "Done Typing!\n You typed " << count << " words\n";
return 0;
}
pretty basic, but I have a question about cin. Does it only freeze the console until enter is pressed if no input stream is detected? When the program starts up it let's me type whatever I wish till I press enter, but even though the same function is called during the while loop it just iterates over buffered input characters until '\n' is reached.
Just odd behavior I hadn't seen from cin and would like some input on exactly why this is, if possible.