Jump to content
  • Advertisement
Sign in to follow this  
Alessandro

C++ std::fstream ... directory separator?

This topic is 2475 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

Hi, I'm puzzled about this matter, maybe you can teach me how it works.

The following code creates a file on Linux/OSX systems just fine:

fstream f:
f.open("/temp/myfile.txt", ios::out);
f << flush:
f.close();

It works also on Win32 systems using this code:

fstream f:
f.open("c:\temp\myfile.txt", ios::out);
f << flush:
f.close();


However, in Win64 systems (compiled, linked to 64 bit and used on a 64bit Windows OS) the file is not created and after some testing I had to replace the dir separator from \ to / , and after that it worked:

f.open("c:/temp/myfile.txt", ios::out);

There is an explanation for that? :huh:

Share this post


Link to post
Share on other sites
Advertisement
Were you escaping the backslash? i.e. doing '\\' instead of just '\'?

Just so you know, you can do '/' on Windows and it'll work as well. I can't remember if that's because Windows will accept '/' as the path separator (which it does), or if it's because the C++ standard says the function will convert the path separator to the OS's default path separator (which I'm not sure about)

Share this post


Link to post
Share on other sites
Also,
ofstream("c:/temp/myfile.txt");
should work just fine and save you a lot of pointless manual open/closing.

Share this post


Link to post
Share on other sites

Also,
ofstream("c:/temp/myfile.txt");
should work just fine and save you a lot of pointless manual open/closing.


Thank you very much!

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!