Tag Archives: C + + Learning

Use of C + + ifstream and error handling

Recently, we are doing the analysis of the text file of prototext: the main reference code is: https://github.com/HoboChen/hoboprototxt

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&)’t.open(fileN)

Solution: Reference: https://stackoverflow.com/questions/43105655/no-matching-call-function-error-for-fstream

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();