Tag: ios stdstring

为什么不std :: fstream类需要一个std :: string?

这不是一个devise问题,虽然它可能看起来像。 (好吧,这是一个devise问题)。 我想知道的是为什么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(); } 这使我一直在处理文件。 当然,C ++库会尽可能使用std::string 。