更新时间:2023-11-08 12:40:52
好的,我是这样做的:
在我的项目属性 -> 配置 -> C/C++ -> 预处理器中,我添加了这个预处理器定义 UNITTESTPRJ="$(ProjectDir)."
然后在我的 cpp 文件中我做了:
Then in my cpp file I did:
#define STRINGIFY(x) #x
#define EXPAND(x) STRINGIFY(x)
string s = EXPAND(UNITTESTPRJ);
s.erase(0, 1); // erase the first quote
s.erase(s.size() - 2); // erase the last quote and the dot
string my_project_dir = s;
最后的愚蠢的.
是为了转义项目目录中尾随的\"
.
The stupid .
at the end was necessary to escape the trailing \"
in the project directory.