Share your repls and programming experiences

← Back to all posts
Quillbert (0)

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

mwilki7 (623)

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;
SPQR (477)

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 :)