问答详情
源自:3-1 C++ 初始String

请问为啥我要敲两次回车?没法解决,求助

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;

}


提问者:慕仙3551312 2019-05-26 12:10

个回答

  • qq_xxxxzhoE
    2020-02-16 20:49:31

    我也是这样,不知道咋回事 我是用vc6.0编译的

  • 慕仙3551312
    2019-05-28 23:07:02

    谢谢你!但是不是这样的,我输入先敲了一次,但没有反应,又敲了一次后面才打印出来,然后又敲了一次界面关闭

  • 莫渡
    2019-05-27 18:02:58

    你疑惑的应该是敲两次回车调试界面才关闭,本来敲一次回车,运算出结果后调式界面会马上自动关闭。但是这个代码中有system("pause");这个代码的作用就是等待用户按一个键然后返回,所以你会觉得要按两次回车,其实按一次回车和其他任意键,界面就会关闭。你也可以试试删掉这行代码,但是你也就没法看到运行结果了,这也是这行代码的作用,让我们有时间看到运行结果。