gpt4 book ai didi

c++ - 在 C++ 中将 projectDir 作为字符串或 char*

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:27:24 24 4
gpt4 key购买 nike

我看到了几个与这个主题相关的问题,但我没有找到简单通用的方法。

我的问题是:如何在我的 C++ 代码中将 $(projectDir) 或另一个宏作为 stringchar*

谢谢

最佳答案

如果你的编译器支持raw strings然后您可以将 MYMACRO=R"($(ProjectDir))"; 添加到预处理器定义(来自 Visual Studio 2013 的屏幕截图): enter image description here

然后您可以将以下内容添加到您的代码中:

#pragma message("MYMACRO == " MYMACRO) // will print project dir during compilation


std::cout << MYMACRO << std::endl; //will print project dir at run time

关于c++ - 在 C++ 中将 projectDir 作为字符串或 char*,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38202907/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com