B. Dutton
B. Dutton

Reputation: 13

C++ "No overloaded function takes 0 arguments" error

I have a program that is saving a username, and the read username function of it keeps giving this error:

Severity Code Description Project File Line Suppression State Error C2661 'std::basic_ifstream>::open': no overloaded function takes 0 arguments ConsoleApplication3 c:\users\main\documents\visual studio 2015\projects\consoleapplication3\consoleapplication3\consoleapplication3.cpp 25

I am very new to C++ and don't understand what this error means, but I have my code here.

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

Upvotes: 1

Views: 1812

Answers (1)

Raindrop7
Raindrop7

Reputation: 3911

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

the line above can be translated as:

ifstream myfile;
myfile.open("Userlog.txt");
myfile >> name2;
myfile.close();

Upvotes: 2

Related Questions