c++ - C/C++ 是否有使用相对路径的跨平台方式?

标签 c++ cross-platform sdl relative-path

我正在用 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/

相关文章:

c++ - 字体渲染函数 C++ SDL 中未处理的异常

c++ - 没有匹配函数调用 ‘Tree<int>::operator==(Tree<int>*&, Tree<int>*&) const’

c++ - 使用 boost 进行半无限积分

c++ - 如何在sql表中查找str

c++ - 读取访问冲突错误

user-interface - 跨平台 GUI 语言/工具包

python - 如何在 Python 中抑制控制台输出?

C: <limits.h> 是跨平台的吗?

c++ - 跨平台,具有异步能力的 C/C++ HTTP 库

c++ - 在 C++ 中,我可以将结构作为指针传递而不在本地声明它吗?