-
little problem
Code:
cout << "Please enter a name for your map:" << endl;
cin.getline(mapName,sizeof(mapName),'\n');
cout << "Enter the number of map rows:" << endl;
cin.getline(rows,sizeof(rows),'\n');
the output is:
Please enter a name for your map:
Enter the number of map rows:
the first question is being skipped...what am i doing wrong? i've use cin.getline() before and never had a problem with it..
thanks.
-
have you used cin>> before the getline anywhere?
Chances are there are crap chars left in cins streambuf so clear them out with a cin.ignore(80,'\n'); before the first getline.
-
I had this problem as well. Untill I bought myself a new book, I couldn't understand why the hel MSVC++ wasn't compiling it right. Because DEV-C++ automatically put this in for me.
-
Consider std::getline(cin, stringObject).
Kuphryn
-
This works with Borland compiler
char rows[20];
char mapName[10];
cout << "Please enter a name for your map:" << endl;
cin.getline(mapName,sizeof(mapName),'\n');
cout << "Enter the number of map rows:" << endl;
cin.getline(rows,sizeof(rows),'\n');
-
thanks very much, everyone. stoned coder's suggestion worked perfectly. i did have a couple cin statements above these getline statements, and i thought that might be the problem. thanks again to all of you!