所以,我已宣布string
名为command
。
那是我的代码:
int main()
{
string username, password, command;
cout << "login as: "; cin >> username;
if (username.substr(username.length()-1) == "s")
{
cout << username << "' password: "; cin >> username;
}
else
{
cout << username << "'s password: "; cin >> password;
}
system("clear");
cout << "Welcome to Shell, " << username << "." << endl << "Type 'help' to see the list of commands." << endl;
cout << "" << endl;
do
{
cout << username << "@localhost -$ ";
getline(cin, command);
} while(1);
}
如果username
的值为admin
,那么输出就是
admin@localhost -$ admin@localhost -$ (here goes the cin)
而不是
admin@localhost -$ (here goes the cin)
。
我该怎么办?感谢。