Jac0b
Jac0b

Reputation: 173

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?

Upvotes: 3

Views: 722

Answers (1)

Jac0b
Jac0b

Reputation: 173

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))?"

Upvotes: 3

Related Questions