Still having a problem with getline. I think it's because cin enters the fail state for some reason. Below is function and output. Any help would be greatly appreciated.
--------------------
Code:
void PrintRecordName()
{
// Precondition:
// Postcondition:
string itemName;
cout << endl << " You entered option 2" << endl << endl;
system("pause");
system("cls");
cout << endl << " Note: You may have to hit enter twice " << endl;
cout << endl << " Please enter item name: ";
getline(cin, itemName,'\n');
while (itemName.find(" ") != itemName.npos)
{
cout << endl << endl << " Please enter a valid item name: ";
getline(cin, itemName,'\n');
}
cout << endl << endl << " You entered: " << itemName << endl << endl;
system("pause");
system("cls");
//GetFile();
//system("pause");
return;
} // ends PrintRecordName function
----------------------
Here's the output I get:
-----------------------
Note: You may have to hit enter twice
Please enter item name: testing testing
Please enter a valid item name: testing testing
You entered:
Press any key to continue . . .
---------------------
I don't understand why the while loop is breaking. The only thing I think of is that cin is in the fail state. I've tried cin.clear() before prompting in the while loop but this also doesn't work.
Out of answers