Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set local environment variables in C++

Tags:

c++

c

manpage

How do I set an environment variable in C++?

  • They do not need to persist past program execution
  • They only need to be visible in the current process
  • Preference for platform independent but for my problem only needs to work on Win32/64

Thanks

like image 505
Jesse Vogt Avatar asked May 22 '09 19:05

Jesse Vogt


People also ask

What is environmental variable in C?

Environment variable is a global variable that can affect the way the running process will behave on the system.

How does Setenv work in C?

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.

What is Putenv in C?

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 .


1 Answers

 NAME         putenv - change or add an environment variable  SYNOPSIS         #include &ltstdlib.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.

like image 173
alamar Avatar answered Sep 25 '22 20:09

alamar