How do I set an environment variable in C++?
Thanks
Environment variable is a global variable that can affect the way the running process will behave on the system.
DESCRIPTION. The setenv() function shall update or add a variable in the environment of the calling process. The envname argument points to a string containing the name of an environment variable to be added or altered. The environment variable shall be set to the value to which envval points.
Description. The putenv() function sets the value of an environment variable by altering an existing variable or creating a new one. The varname parameter points to a string of the form var=x, where x is the new value for the environment variable var .
NAME putenv - change or add an environment variable SYNOPSIS #include <stdlib.h> int putenv(char *string); DESCRIPTION The putenv() function adds or changes the value of environment variables. The argument string is of the form name=value. If name does not already exist in the environment, then string is added to the environment. If name does exist, then the value of name in the environment is changed to value. The string pointed to by string becomes part of the environment, so altering the string changes the environment.
On Win32 it's called _putenv I believe.
See SetEnvironmentVariable also if you're a fan of long and ugly function names.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With