Class design std :: ifstream

Those of us who have seen the beauty of STL try to use it as much as possible, and also encourage others to use it wherever we see them, using raw pointers and arrays. Scott Myers wrote an entire book on STL, titled Effective STL . But what happened to the developers ifstream, what they preferred char*over std::string. I wonder why the first parameter ifstream::open()is of type const char*instead const std::string &. Please see his signature:

void open(const char * filename, ios_base::openmode mode = ios_base::in );

Why is this? Why not this:

void open(const string & filename, ios_base::openmode mode = ios_base::in );

Is this a serious design mistake? Or is this design intentional? What could be the reason? I see no reason why they preferred char*over std::string. Please note that we could pass the char*last function that takes std::string. It's not a problem!

By the way, I know what ifstreamtypedef is, so no comments on my headline .: P. It looks short, so I used it.

Actual template template:

template<class _Elem,class _Traits> class basic_ifstream;
+5
source share
3 answers

My copy of the standard does not agree with you. He says this is overload:

void open(const char* s, ios_base::openmode mode = ios_base::in);
void open(const string& s, ios_base::openmode mode = ios_base::in);

, ++ 0x.

, iostreams std::basic_string, , , - #include <string> , .

+4

IOStream , STL . string. , IOStream .

BTW, , ++ 0X, .

+7

, C std::string, std::string C, , , , , std::ifstream , , const char* , .

?

? const std::string& ?

std::string, , - , std::string . ++ .c_str() , , , .

0
source

All Articles