c++ - 如何缩短图像的文件名/路径,使其适用于所有机器

标签 c++ xcode macos sfml search-path

在我使用 sfml 库和 xcode 的 C++ 程序中,当我加载图像时,我需要像 picture.loadFromFile("Users/username/Desktop/Xcode/Game/Sprites/MyImage.png") 一样加载它 无论如何我可以将该路径缩短为 "Game/Sprites/MyImage.png"。我再次使用 xcode 和 mac。谢谢。

最佳答案

您可以使用正则表达式:

#include <regex>

std::string full_path = "Users/username/Desktop/Xcode/Game/Sprites/MyImage.png";
std::smatch _match;
std::regex _regex("Game.*");
if(std::regex_search(full_path, _match, _regex))
  std::string relative_path = _match.str(); //"Game/Sprites/MyImage.png"

关于c++ - 如何缩短图像的文件名/路径,使其适用于所有机器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48997031/

相关文章:

c++ - 分析_mm_setzero_ps和{0.0f,0.0f,0.0f,0.0f}

c++ - OpenCV 3:可用的 FeatureDetector::create() 和 DescriptorExtractor::create() 选项列表?

c++ - 在指向父对象的指针上初始化子对象

linux - 脚本找不到文件

python - 如何将 Python 2.7 设为 Mac 的默认 Python 版本?

macos - 在 Mac OS X 中禁用鼠标加速

c++ - 这个 C++ 类声明是什么意思?

ios - swift4 中 Core Data 的单元测试用例

ios - Apple Mach-O-Linker 错误 CocoaPods

ios - Apple文档中的 "must reside at the top level of the app bundle"是什么意思?