Sign in to follow this  
Alessandro

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

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this