在我使用 sfml 库和 xcode 的 c++ 程序中,当我加载图像时,我需要加载它picture.loadFromFile("Users/username/Desktop/Xcode/Game/Sprites/MyImage.png")
,无论如何我可以将该路径缩短为"Game/Sprites/MyImage.png"
. 我再次使用 xcode 和 mac。谢谢。
1 回答
1
您可以使用正则表达式:
#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"
于 2018-02-26T21:49:13.140 回答