Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct syntax for portable fstream file paths?

I have seen this annoying question again and again. Could you please share your knowledge that might help us to find the answer.

My confusion is that, forward-slash is posix standard but directory structure of operating systems are different.

Thank you

What is the correct syntax for portable fstream file paths?

(e.g. the string you would pass to std::fstream:open() to open a file.)

A. "::directory:file.bin"

B. "C:/Directory/File.bin"

C. "/directory/file.bin"

D. "C://Directory//File.bin"

E. std:fstream file paths are not portable.

like image 733
Validus Oculus Avatar asked Dec 25 '22 22:12

Validus Oculus


1 Answers

E : not portable, i.e. implementation defined

Answer can be found in the std::fopen docs: (which are referred to by fstream via filebuf::open)

Notes

The format of filename is implementation-defined, and does not necessarily refer to a file (e.g. it may be the console or another device accessible through filesystem API). On platforms that support them, filename may include absolute or relative filesystem path.

like image 155
Martin Ba Avatar answered Dec 28 '22 22:12

Martin Ba