这不是一个设计问题,确实如此,尽管看起来可能如此。 (好吧,这是一个设计问题)。我想知道的是为什么C++ std::fstream
类不在其构造函数或开放方法中使用std::string
。每个人都喜欢这样的代码示例:为什么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
?
该示例不应对重载解析规则造成任何歧义。 `f(char *,std :: string)`是[精确匹配](http://www.lcdf.org/c++/clause13.html#s13.3.3.1.1),而其他的则需要转换,因此首先是最好的可行功能。如果你删除了第一个`f`,那么就像[(char *&,std :: string&) - >(char *,std :: string) - >(char *,char *))[更好的转换序列](http://www.lcdf.org/c++/clause13.html#s13.3.3)比“(char *&,std :: string&) - >(char *,std :: string) - >(std: :string,char *)“,第二个`f`将是最好的可行函数。我错过了什么吗? – outis 2010-11-14 23:49:43