C++ でローカル環境変数を設定する

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.

Win32 では _putenv と呼ばれていると思います。

長くて醜い関数名が好きなら、SetEnvironmentVariable も参照してください。


環境変数は、このプログラムの実行以外では使用されないため、必要なものであることに肯定的ではありません。 OS を使用する必要はありません。

これらすべての値を保持するシングルトン クラスまたは名前空間を用意し、プログラムの開始時に初期化する方がよい場合があります。