file paths for multi-platform program?

Hi -

I'm writing a C++ program that must run on both Mac and Windows. The code itself is portable enough, but I'm having trouble figuring out how to handle file paths. My program uses two directories/folders: one for input, one for output. How might one handle this?

The real rub is the Mac OS creation of a "package" for its executables. I can't see how to get around this without the use of absolute file names.

Any suggestions?
Don't both Windows and Mac give the application path as the first argument?
http://en.wikipedia.org/wiki/Main_function#C_and_C.2B.2B
Unless your goal is NOT to use absolute paths?
Last edited on
I'd prefer relative pathnames. I guess if I take the absolute pathname and edit it to form the paths to my other directories, that would work. I'll have to allow for the fact that Mac OS and Windows use different folder delimiters ("/" vs. "\") and there may be some other snags in there.

It would be nice if I could just use "../other-directory-name" but even this will require a conditional compile (for the delimiter). No really clean solution, is there?
argv[0] is only the program name as was given to the shell (e.g. "program", "..\program", "\program"). The working directory need not, and generally will not, be included.

Windows accepts forward slashes. It's kind of puzzling that they're accepted at the API level but not at the UI level, isn't it?
Yeah, I think it's because at the UI level the forward slashes make it look on the internet instead. :/
Thanks, helios. Currently I'm launching my program from Qt, and it seems to form the entire pathname as the first argument.

Good information about Windows and the "/"...I also ran across the example in this page last night:

http://www.cplusplus.com/reference/string/string/find_last_of/

So I guess there are options. Now I just have to figure out getting around the package issue of the Mac, and I should be OK.
you can use boost filesystem for that. http://www.boost.org/doc/libs/1_48_0/libs/filesystem/v3/doc/index.htm (the doc is not so good unfortunately)

Better use absolute path instead. Because relative path can be misleading
Topic archived. No new replies allowed.