开发者

C++ preprocessor path root

开发者 https://www.devze.com 2023-02-07 13:17 出处:网络
Is it possible to process a file path using the C++ preprocessor? What I want is this GETROOT(开发者_如何学运维 __FILE__ )

Is it possible to process a file path using the C++ preprocessor?

What I want is this GETROOT(开发者_如何学运维 __FILE__ ) expanding into \\myserver\myshare\

Supposing that the path to the file is something like \\myserver\myshare\folder\folder\file.txt

I'm using mcpp on Windows XP


Depends on the compiler, the preprocessor behaves slightly different on GCC/Microsoft etc. There is not standard-conform way to do that..

On Windows you might try to use build environment variables. Visual Studio can expose these values ($(SolutionDir) etc) to the preprocessor context. Just add a preprocessor value like ROOT_PATH="$(SolutionDir)" (C/C++ -> preprocessor in project settings).


No, it's not, at least not in a standard way. I couldn't say for sure that there are no compilers anywhere in the world that do it, but it seems unlikely.

What's the use-case that means you can't do it at runtime?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号