慕仙3551312
2019-05-26 12:10
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;
}
我也是这样,不知道咋回事 我是用vc6.0编译的
谢谢你!但是不是这样的,我输入先敲了一次,但没有反应,又敲了一次后面才打印出来,然后又敲了一次界面关闭
你疑惑的应该是敲两次回车调试界面才关闭,本来敲一次回车,运算出结果后调式界面会马上自动关闭。但是这个代码中有system("pause");这个代码的作用就是等待用户按一个键然后返回,所以你会觉得要按两次回车,其实按一次回车和其他任意键,界面就会关闭。你也可以试试删掉这行代码,但是你也就没法看到运行结果了,这也是这行代码的作用,让我们有时间看到运行结果。
C++远征之封装篇(上)
103393 学习 · 732 问题