accessing environment variables
char * getenv(const char * name);
Alternately, environment variables may be accessed by using the special form of main():
int main(int argc, char * argv[], char *envp[]);
At startup, the variable envp Is set to point to the process's environment, which is in the form of an array of C-strings. The last element in the array is a NULL pointer indicating the end of the array. This enables you traverse the entire array easily:
//execute loop so long as envp[n] isn't NULL
for (int n=0; envp[n]; n++) {
cout << envp[n]<< endl;
}
setting environment variables
int putenv(const char * var);
var must be of the form varname=value. This does not affect the master environment, only the copy used by the currently running program, which is then inherited by any child processes.
References:
http://www.informit.com/guides/content.aspx?g=cplusplus