Well I am coding a small intermediate program to help me with learning c++ , and i am wondering how to check for blank input to cin >> string

heres what i have

string name;

cout << "Enter You're Name: ";
getline(cin, name);

and if i just hit enter without typing any name the program just stays blank

it is a console app btw

Recommended Answers

All 3 Replies

add some check to name.

if (name.empty()){
 cout <<"You entered nothing..."<<endl;

loop through it and make sure at least one character isn't a space would also tell you.

Oh, and it's "Your" instead of "You're", you're = you are

Use a loop:

string name;

cout << "Enter You're Name: ";
  getline(cin, name);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.