为了账号安全,请及时绑定邮箱和手机立即绑定

为什么我用了getline(cin,name)运行程序时,输入字符串后按回车没有反应,而改成cin就可以了?

为什么我用了getline(cin,name)运行程序时,输入字符串后按回车没有反应,而改成cin就可以了?

正在回答

1 回答

// 我没有遇到这个问题,代码是这样的。

#include <iostream>

#include <stdlib.h>

#include <string>


using namespace std;


int main(void)

{

    string name;

    cout << "Please input your name:";

    getline(cin, name);

    if(name.empty())

    {

        cout << "input is null." << endl;

        return 1;

    }

    if(name == "imooc")

    {

        cout << "you are a administractor" << endl;

    }

    cout << "hello " + name << endl;

    cout << "your name length:" << name.size() << endl;

    cout << "your name first letter is:" << name[0] << endl;


    return 0;

}


1 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
C++远征之封装篇(上)
  • 参与学习       103381    人
  • 解答问题       732    个

封装--面向对象的基石,本教程力求帮助小伙伴们即学即会

进入课程

为什么我用了getline(cin,name)运行程序时,输入字符串后按回车没有反应,而改成cin就可以了?

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号