这不是一个设计问题,实际上,虽然看起来像它.(好吧,好吧,这是一个设计问题).我想知道的是为什么C++ std::fstream类不会std::string在构造函数或开放方法中使用它们.每个人都喜欢代码示例:
#include <iostream>
#include <fstream>
#include <string>
int main()
{
std::string filename = "testfile";
std::ifstream fin;
fin.open(filename.c_str()); // Works just fine.
fin.close();
//fin.open(filename); // Error: no such method.
//fin.close();
}
Run Code Online (Sandbox Code Playgroud)
这使我一直处理文件.当然,C++库会std::string尽可能使用?