C ++"没有重载函数需要0个参数"错误

时间:2016-10-19 00:15:21

标签: c++ ifstream

我有一个保存用户名的程序,它的读取用户名功能一直给出错误:

  

严重级代码描述项目文件行抑制状态   错误C2661' std :: basic_ifstream> :: open&#39 ;:没有重载的函数需要0参数ConsoleApplication3 c:\ users \ main \ documents \ visual studio 2015 \ projects \ consoleapplication3 \ consoleapplication3 \ consoleapplication3.cpp 25

我对C ++很陌生,不明白这个错误意味着什么,但我的代码在这里。

string name2()
{
    string name2;
    ifstream myfile("Userlog.txt");
    myfile.open();
    myfile >> name2;
    myfile.close();
    return name2;
}

1 个答案:

答案 0 :(得分:2)

string name2;
ifstream myfile("Userlog.txt"); // here you are calling open
myfile.open(); // no version of ifstream. so open what??!!!

上面的行可以翻译为:

ifstream myfile;
myfile.open("Userlog.txt");
myfile >> name2;
myfile.close();
相关问题