문제 설명
ifstream input_file(filename); (I am receiving an error "no matching function to call" in the line ifstream input_file(filename);)
6
int main(int argc, const char * argv[]) {
cout << "Give the name of the input file : ";
string filename;
cin >> filename;
cout << "Reading from " << filename << "..." << endl;
ifstream input_file(filename);
if( !input_file ) {
// stuff...
}
}
</code></pre>
참조 솔루션
방법 1:
Assuming you have #include <fstream>
and using namespace std;
in your code, then change this:
ifstream input_file(filename);
To this:
ifstream input_file(filename.c_str());
In your compiler's version of C++, the std::ifstream
constructor takes only a const char*
as input, not a std::string
. C++11 is needed to pass in a std::string
as‑is. If your compiler supports C++11, maybe you have not enabled it. Check your compiler's documentation.
(by user12841327、Remy Lebeau)
참조 문서