As you know, file streams do not have a constructor, which the string object would take as an argument. Who knows why? Did it happen historically or does this have any meaning?

  • What are you talking about? - alexlz
  • About the reasons - skegg
  • "file streams do not have a constructor that the string object would take as an argument" - is this about? Can you explain on the fingers? - alexlz
  • string name ("name"); ofstream fs (name); - in C ++ 03 there will be an error - skegg
  • one
    @asen, hello, come. There are C file streams, which are implemented as structures, and C ++, which are the most real objects, with inheritance, constructors, and other OOP charms. - skegg

1 answer 1

You can probably say that iostreams is the oldest part of the standard library and that is why there is everything on the const char* , but this is some kind of bad explanation.

It seems to me that this constructor was simply forgotten in the C++03 standard and added already in C++11 for convenience, for no particular reason. Actually, this is understandable, since one can switch from one constructor to another by calling c_str() or wrapping const char* in std::string .

The new standard on this occasion even accurately states that:

the effect of stream(string) equivalent to the effect of stream(string.c_str())


By the way, in C++11 , for example, they forgot std::make_unique (which is boost::make_shared ).

  • @Angry Bird gramota.ru/spravka/punctum/58_426 :) - Costantino Rupert
  • I never met "probably" as an introductory word, considered it appropriate only as an adverb, i.e. without commas. Probably = sure so. Probably = probably. - angry