Skip to content
← Back to Community
Bug?
Profile icon
Quillbert

The getline doesn't seem to work. May just be incompetent programming, so I wanted to see if this was a bug.

Voters
Profile icon
KathyMorales
Profile icon
Quillbert
Comments
hotnewtop
Profile icon
mwilki7

cin and getline, if I recall correctly, don't handle newline characters '\n' the same. I recommend sticking with just one or the other.
cin still works for strings

int main() { int age = -1; string name; cout << "Enter your age: "; cin >> age; cout << age << endl; cout << "Enter you name: "; cin >> name; cout << name << endl; cout << "Enter age again: "; cin >> age; cout << age << endl; return 0; }
Profile icon
SPQR

Don't use cin and getline(cin) together, they aren't really compatible. Use only getline(cin) or only cin for all of the vars and it should fix your problem :)