Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use environment var in source code ( Compiling time )

How can I use an environment variable, say %WINDIR% in VS? I tried in Properties > Preprocessor > Definitions > I added: ENV_VAR="($Windir)"

in my .cpp:
std::string s = ENV_VAR

but when executed it prints:

C:windows

How do I fix this?

like image 297
Jac0b Avatar asked Aug 02 '26 23:08

Jac0b


1 Answers

Found the solution:

How to get a Visual Studio Macro Value into a pre processor directive?

in my example I should add: ENV_VAR=R"?($(WINDIR))?"

like image 118
Jac0b Avatar answered Aug 05 '26 14:08

Jac0b