I know that iostream would have buffers to store I/O data. Say, I have some C++ code like this. C++ code Since StackOverflow doesn't allow me to embed an image to this question yet, here's the code in case you don't want to click on the link.
int main(){
int Val1, Val2;
string String_Val;
cin >> Val1;
cin >> Val2;
cin.ignore(1);
getline(cin, String_Val);
}
Why does the cin.ignore(1) work? Here's
My idea of how the buffer looks like.
Wouldn't the buffer have two \n like \n\n because I hit the Return/Enter key twice by cin>> Val1 and then by cin>>Val2. And according to this StackOverflow question cin>> should leave the \n in the stack. Thus, I thought only cin.ignore(2), which discards two first chars in the buffer, works. Also,
getline(cin >> ws, String_Val);
works as well according to this StackOverflow thread. Shouldn't ws remove whitespaces only, and shouldn't whitespaces be represented differently from newline \n in the buffer?
Lastly, it would really help if someone happens to know any interactive program or ways to help me visualize the buffer as the program runs. Something like https://visualgo.net.
Thanks a ton!