This isn't a design question, really, though it may seem like it. (Well, okay, it's kind of a design question). What I'm wondering is why the C++ std::fstream
classes don't take a std::string
in their constructor or open methods. Everyone loves code examples so:
#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();
}
This gets me all the time when working with files. Surely the C++ library would use std::string
wherever possible?
f(char*,std::string)
is an exact match while the others would require conversion, hence the first would be the best viable function. If you removed the firstf
, then, as "(char*&,std::string&) -> (char*,std::string) -> (char*,char*)" is a better conversion sequence than "(char*&,std::string&) -> (char*,std::string) -> (std::string,char*)", the secondf
would be the best viable function. Am I missing something? – Gumbotil