C
Christopher
I am trying to get a line from the user which could be anything, I am
expecting either a string followed by a whitespace or just a string by
itself. I have tryed using string::getline, stringstreams, and all
sorts of cin variations and can't get it right. Currently my program
stops, waiting for more input in the case the user just enters a
command with no argument, in this block of code. How can I fix it up?
void Menu()
{
string command;
int argument;
string::size_type index = string::npos;
while(command != "quit")
{
cout<<"\nThe Following are valid commands:\n";
cout<<"read_all <number> -- display entire mail header and body.\n";
cout<<"read <number> -- display body of message\n";
cout<<"del <number> -- delete message\n";
cout<<"undel -- undo all deletion\n";
cout<<"reply <number> -- reply to message\n";
cout<<"list <number> -- display the next 10 message
summaries\n";
cout<<"quit -- exit this program\n\n";
cin>>command;
if(!(cin>>argument))
argument = 0;
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
if(command == "read_all")
cout<<"not implemented\n";
else if(command == "read")
cout<<"not implemented\n";
else if(command == "del")
cout<<"not implemented\n";
else if(command == "undel")
cout<<"not implemented\n";
else if(command == "reply")
cout<<"not implemented\n";
else if(command == "list")
cout<<"not implemented\n";
}
}
Thanks,
Christopher
expecting either a string followed by a whitespace or just a string by
itself. I have tryed using string::getline, stringstreams, and all
sorts of cin variations and can't get it right. Currently my program
stops, waiting for more input in the case the user just enters a
command with no argument, in this block of code. How can I fix it up?
void Menu()
{
string command;
int argument;
string::size_type index = string::npos;
while(command != "quit")
{
cout<<"\nThe Following are valid commands:\n";
cout<<"read_all <number> -- display entire mail header and body.\n";
cout<<"read <number> -- display body of message\n";
cout<<"del <number> -- delete message\n";
cout<<"undel -- undo all deletion\n";
cout<<"reply <number> -- reply to message\n";
cout<<"list <number> -- display the next 10 message
summaries\n";
cout<<"quit -- exit this program\n\n";
cin>>command;
if(!(cin>>argument))
argument = 0;
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
if(command == "read_all")
cout<<"not implemented\n";
else if(command == "read")
cout<<"not implemented\n";
else if(command == "del")
cout<<"not implemented\n";
else if(command == "undel")
cout<<"not implemented\n";
else if(command == "reply")
cout<<"not implemented\n";
else if(command == "list")
cout<<"not implemented\n";
}
}
Thanks,
Christopher