I've started learning C++ and was working on a program that asks for a user's age and name. The age section works fine, but when I try to get the user's name using getline(cin, name), it skips the input and just goes on without capturing anything. Can anyone help me understand what's going wrong? I appreciate any assistance!
2 Answers
It sounds like you might be running into an issue with the input buffer. If you've used cin before getline, there could be a newline character left in the buffer that's causing getline to skip the input. Try checking out this explanation: [Stack Overflow Link Here]. Posting your actual code would help too!
No problem! Let me know if that helps!
Can you share your code? That'll make it easier to figure out what's going on!
Sure! Here's my code:
```cpp
string name;
cout << "Now, enter your name... NOW!!!!" << endl;
cout << "---->";
getline(cin, name);
cout << "Really? " << name;
cout << " is your name... a whole ";
cout << name.length();
cout << " letters" << endl;
cout << "weirdo... gtfo" ;
```
Hope this helps!

Thanks, I didn't think to post the code here. I’ll take a look at that link!