为什么getline()函数不起作用......? [英] Why getline() function is not working...?

查看:378
本文介绍了为什么getline()函数不起作用......?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了getline功能但它不能正常工作......请帮助..请查看下面的代码:

I used getline function BUT it is not working...Please Help..Ckeck this Code below:

#include <iostream>
#include <conio.h>
#include <string>
#include <fstream>

using namespace std;

class notepad
{
    string A;

public:

     void newnotpad()
    {
        char name[100];
        cout<<"Enter Name/Path of File: ";
        cin>>name;
        cout<<endl;
        cout<<"Enter Text to New Notepad: "<<endl<<endl;
        getline(cin,A);
        myfile.open(name);
        myfile<<A;
        myfile.close();
    }

};

int main()
{
    notepad x;
    x.newnotpad();
}

推荐答案

尝试添加

Try adding
cin.ignore();

紧跟在

cin >> name;



(参见此处 [ ^ ])


这篇关于为什么getline()函数不起作用......?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆