I am using std::string to parse a command given by the user, I don't
understand why the following snippet is not working as expected.
string buffer, // store commands from user
command,
argument;
string::size_type index = string::npos;
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>>buffer;
index = buffer.find_first_of(' ');
if(index != string::npos )
{
cout<<"first\n";
command = buffer.substr(0, index);
buffer.erase(0, index);
argument = buffer;
}
else
{
cout<<"second\n";
command = buffer;
argument = "";
}
cout<<index<<"\n";
cout<<command<<" "<<argument<<"\n
my input:
hello there
output:
second
4294967295
helllo
expected output:
first
6
hello there
Thanx,
Chris