I'm running a few tests by playing around with the member functions of C++ and I'm confused on why sometimes get()
doesn't read a new-line character. I've used a do-while loop to test and it seems to work that way, but not with a traditional if-else statement.
Let's say input is The\n.
#include <iostream>
using namespace std;
int main()
{
char test;
cin.get(test);
cin.get(test);
cin.get(test);
cin.get(test);
if (test == '\n')
{
cout << "Test successful!";
}
}
It doesn't seem to read '\n' at all. Is there something I'm not getting here?