0

so I'm a newbie at C++, and I've been poking around on the internet on how to do this, and so far I have this:

void includeFile(string name){ ifstream ifs; ifs.open(name); string commands; while (getline(ifs,commands)){ commandReader(ifs); } ifs.close(); } 

(commandReader is a function that takes an istream)

When I try to compile, I get the error "no matching function for call" and then gives me the line number for the ifs.open(name) line. I've included fstream, so not sure why it's doing this

1
  • In the future, try a reference. Note that there are two overloads of the function and one of them is available in C++11. Commented Jun 21, 2015 at 6:45

2 Answers 2

1

Sorry, never mind; found the answer right after I posted this. The solution was to have name.c_string() as the parameter instead, as string support was only added in c++11

Sign up to request clarification or add additional context in comments.

Comments

0

As @chris pointed out, pre-C++11, ifs.open expects a char*, not an std::string. Try ifs.open(name.c_str()).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.