Jump to content
  • Advertisement
Sign in to follow this  
dnsauve

std::string and fstream

This topic is 4805 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Just curious about why I can't pass a std::string to an fstream constructor. Am I the only person that thinks it's odd that you have to pass a char array?

Share this post


Link to post
Share on other sites
Advertisement
Thanks, this actually what I've been doing... Doesn't make for very elegant looking code though. Yuck.

Is this just Microsoft's implementation of STL or is that just the way it is?

Share this post


Link to post
Share on other sites
I would say it's the standard. And consider it rather sane.
You should always strive to decouple things as much as possible and this is an excellent example. Having std::fstream dependant on std::string would be nutty what if clients don't need want desire or even afford (memory can be expensive sometimes) to link to std::string why would they need to when all the ctor really wants is a string representing a filename?

Share this post


Link to post
Share on other sites
Fair enough.

But, why couldn't the fstream ctor be overloaded to take a std::string as well as the standard char array?

Share this post


Link to post
Share on other sites
Quote:
Original post by dnsauve
Fair enough.

But, why couldn't the fstream ctor be overloaded to take a std::string as well as the standard char array?


Since then it would be dependant on std::string anyhow because it's visible in the interface.

But if it bothers you why not simply create a convinence function to handle it that's how you usually glue togheter libraries :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!