fgfjhgrjr erjhm
fgfjhgrjr erjhm

Reputation: 335

ifstream arguments - C++

I Declared: std::string input_file="1.txt"; then I tried to do this command:

static ifstream myfile (input_file);

and I get the error: no matching function for call to : std::basic_ifstream<char>::basic_ifstream(std::string&)

Upvotes: 1

Views: 507

Answers (1)

Magnus Hoff
Magnus Hoff

Reputation: 22099

Try:

static ifstream myfile(input_file.c_str());

For some reason, the ifstream constructor doesn't accept an std::string.

Upvotes: 6

Related Questions