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