Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C/C++ Is there any cross plataform way of using relative paths?

I'm programming a little game in SDL and the files are structured like this:

"src/game/" have both .h and .cpp source files.

"data/" have the game files like maps, tilesets, sprites and so on...

to load a sprite for example I would use the following code.

spriteLib.loadSprite("data/sprites/sprite-ghost.bmp");

to convert this string to an absolute path I have those lines in the first 4 lines of the function:

SSprite CSpriteLib::loadSprite(std::string file)
{
    //Converting the file path
    char converted[128];
    realpath(file.c_str(),converted);
    file = converted;

But this way the program only compiles under liux so... if anyone knows another way to do that I would be grateful.

like image 605
bardes Avatar asked Jan 20 '23 21:01

bardes


1 Answers

Boost is your friend. Here's a link to the Boost Filesystem tutorial.

like image 135
axw Avatar answered Jan 23 '23 11:01

axw