我正在用 SDL 编写一个小游戏,文件结构如下:
"src/game/"有 .h 和 .cpp 源文件。
"data/"有游戏文件,比如 map ,tilesets, Sprite 等等...
例如,要加载 Sprite ,我会使用以下代码。
spriteLib.loadSprite("data/sprites/sprite-ghost.bmp");
要将此字符串转换为绝对路径,我在函数的前 4 行中有这些行:
SSprite CSpriteLib::loadSprite(std::string file)
{
//Converting the file path
char converted[128];
realpath(file.c_str(),converted);
file = converted;
但这样程序只能在 liux 下编译,所以...如果有人知道另一种方法,我将不胜感激。
最佳答案
Boost 是您的 friend 。这是 Boost Filesystem 的链接教程。
关于c++ - C/C++ 是否有使用相对路径的跨平台方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4506367/