Use of C + + ifstream and error handling

Recently, we are doing the analysis of the text file of prototext: the main reference code is:

In the process of drawing a cat according to a tiger, some mistakes occurred. The record is as follows:

Errors in use:

1.error: no matching function for call to ‘std::basic_ ifstream<char>::open(const string&)’

Solution: Reference:

This mainly means that when the open function is used, the parameter type specified by the function is const char *, but a string type parameter is passed in the process of using it. At this time, the string type parameter needs to be converted to the parameter type required by open. A method proposed in the reference is to use C_ str();


Read More: