[Error] no matching function for call to 'std::basic_ofstream<char>::basic_ofstream(std::string&)'
时间: 2023-09-15 10:16:36 浏览: 186
image-matching.rar_image matching_site:www.pudn.com_同名点匹配_相关系数_相
This error occurs when the std::ofstream constructor is given a string argument instead of a character array (const char*) argument. To fix this error, you can pass the string argument as a c_str() of the string, like this:
```
std::string filename = "example.txt";
std::ofstream outfile(filename.c_str());
```
Alternatively, you can use the constructor that takes a std::string_view argument, which was introduced in C++17:
```
std::string filename = "example.txt";
std::ofstream outfile(std::string_view(filename));
```
阅读全文