Correct me if I'm wrong, shouldn't this code pause for user input at cin.getline()? Seems like it's skipping for me.
Code:void GetName(){ char Name[50]; cout<<"Please Enter your name: "; cin.getline(Name,50); cout<<Name<<", is this correct?\n"; }
This is a discussion on String problem within the C++ Programming forums, part of the General Programming Boards category; Correct me if I'm wrong, shouldn't this code pause for user input at cin.getline()? Seems like it's skipping for me. ...
Correct me if I'm wrong, shouldn't this code pause for user input at cin.getline()? Seems like it's skipping for me.
Code:void GetName(){ char Name[50]; cout<<"Please Enter your name: "; cin.getline(Name,50); cout<<Name<<", is this correct?\n"; }
Yes, but perhaps there is a newline left in the input buffer, so the cin.getline consumes that line.
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
try and flush it.
Code:flush(cout);
Thanks, got it working now!
>> char Name[50];
>> cout<<"Please Enter your name: ";
>> cin.getline(Name,50);
Should be
std::string Name;
std::cout << "Please Enter your name: ";
std::getline(Name, std::cin);
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^