請問為啥我要敲兩次回車?沒法解決,求助
int main(){
string name;
cout << "please enter yourname:";
getline(cin, name);
if (name.empty())
{
cout << "your name is null" <<endl;
system("pause");
return 0;
}
if (name == "imooc")
cout << "you are a adminisriter" << endl;
cout << "hello" + name << endl;
cout << "the first letter of your name is:" << name[0] << endl;
cout << "the length of your name :" << name.size() << endl;
system("pause");
return 0;
}
2020-02-16
我也是這樣,不知道咋回事 我是用vc6.0編譯的
2019-05-28
謝謝你!但是不是這樣的,我輸入先敲了一次,但沒有反應,又敲了一次后面才打印出來,然后又敲了一次界面關閉
2019-05-27
你疑惑的應該是敲兩次回車調試界面才關閉,本來敲一次回車,運算出結果后調式界面會馬上自動關閉。但是這個代碼中有system("pause");這個代碼的作用就是等待用戶按一個鍵然后返回,所以你會覺得要按兩次回車,其實按一次回車和其他任意鍵,界面就會關閉。你也可以試試刪掉這行代碼,但是你也就沒法看到運行結果了,這也是這行代碼的作用,讓我們有時間看到運行結果。