在C ++中将projectDir作为字符串或char *获取 [英] getting projectDir as a string or char* in c++

查看:70
本文介绍了在C ++中将projectDir作为字符串或char *获取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了几个与此主题相关的问题,但是我没有发现简单而通用的方法.

I saw a couple of questions relevant to this topic, but I didn't found the easy and common way to do this.

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

My question is: How can I have $(projectDir) or another Macro as a string or char* in my C++ code?

谢谢

推荐答案

如果您的编译器支持添加到预处理器定义中(Visual Studio 2013中的屏幕截图):

If your compiler supports raw strings then you can add MYMACRO=R"($(ProjectDir))"; to preprocessor definitions (screenshot from Visual Studio 2013):

然后,您可以在代码中添加以下内容:

Then you can add the following to your code:

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


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

这篇关于在C ++中将projectDir作为字符串或char *获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆