為什么我的輸入需要多點(diǎn)一次回車
為什么我的輸入需要多點(diǎn)一次回車
#include <iostream>
#include <string>
using namespace std;
int main()
{
? ? string name;
? ? cout<<"請(qǐng)輸入你的名字:"<<endl;
? ? //輸入的字符存在name中,如果用cin輸入空字符將不會(huì)繼續(xù)執(zhí)行
? ? getline(cin,name);
? ? //判斷輸入是否為空
? ? if(name.empty())
? ? {
? ? cout<<"輸入為空!"<<endl;
? ? return 0;
? ? }
? ??
? ? if(name=="imooc")
? ? {
? ? cout<<"你是管理員"<<endl;
? ?
? ? }
? ??
? ? cout<<"Hello "<<name<<endl;
? ? cout<<name.size()<<endl;
? ? cout<<name[0]<<endl;
? ??
? ? return 0;
}
2017-03-28
?cout<<"請(qǐng)輸入你的名字:"<<endl; ?這句去掉<<endl