Hi I was just looking up the difference between cin.get() and cin.getline().
It seems they can both function the same way except cin.get() keeps the delimiter in the buffer while cin.getline() throws it out.
My question is with this code:
char name; char name1; char name2; string hi; cin >> hi; cout << hi << endl; cin.get(name, 255); cout << "name " << name << "!" << endl; cin.getline(name1,255); cout << "name1 " << name1 << "!" << endl; cin.getline(name2, 255); cout << "name2 " << name2 << "!" << endl;
From what I read on online articles the cin >> hi should input into hi one word but leave the '\n' delimiter in the butter. The cin.get(name, 255) would then skip over user input because it sees '\n' right away. Then cin.getline(name1, 255) should also roll over right away because cin.get(name, 255) would not have thrown away the delimiter.
However my issue is the first cin.getline() should have thrown away the '\n' but for some reason it also skips over the second cin.getline(name2, 255) as if there is another '\n' that it reads immediately. It works as I expected when during the cin >> hi I leave a space at the end of my input ex:"hello " but if I do "hello" it rolls over all 3 get functions.
Why does it do this? Does the cin >> hi leave more than one '\n' in the buffer?