Reputation: 2809
Well, I think the question is fairly objective. So, is there anyway to do it?
Actually, I need to check what version of the OS because I want to get a directory from a string:
"directory/file.ext"
or
"directory\file.ext"
So I split one of those strings according to "\" or to "/", depending on which OS I'm dealing with.
I'm quite new to C++ and I don't know if there's another way of getting a directory from a path string.
I can do that fairly well with C#, which will be my last alternative.
Best regards and thanks in advance!
Upvotes: 3
Views: 635
Reputation: 67527
You can use #ifdef WIN32
to decide if you are on Windows. This works even on 64-bit Windows.
Upvotes: 1
Reputation: 4468
Actually, you don't need to do that. The POSIX style "/" will work as a directory separator just fine, even on a Win32 system (try it out.)
That said, other filesystem operations are platform-specific (drive letters, for instance.)
The Boost Filesystem library is a good option - code to this, and it will handle the platform details for you: http://www.boost.org/doc/libs/1_31_0/libs/filesystem/doc/index.htm
Other cross-platform C++ frameworks, such as Qt, have similar facilities.
You can delve into more details here: http://en.wikipedia.org/wiki/Path_(computing)
Upvotes: 5