环境名称Environment Names

ANSI 4.10.4.4 环境名称集和用于更改 getenv 函数使用的环境列表的方法ANSI 4.10.4.4 The set of environment names and the method for altering the environment list used by the getenv function

环境名称集是不受限的。The set of environment names is unlimited.

若要从 C 程序中更改环境变量,请调用 _putenv 函数。To change environment variables from within a C program, call the _putenv function. 若要从 Windows 命令行中更改环境变量,请使用 SET 命令(例如,SET LIB = D:\ LIBS)。To change environment variables from the command line in Windows, use the SET command (for example, SET LIB = D:\ LIBS).

C 程序内的环境变量集仅在操作系统命令外壳(CMD.EXE 或 COMMAND.COM)的主机副本运行时存在。Environment variables set from within a C program exist only as long as their host copy of the operating system command shell is running (CMD.EXE or COMMAND.COM). 例如,行For example, the line

system( SET LIB = D:\LIBS );  

将运行命令外壳 (CMD.EXE) 的副本、设置环境变量 LIB 并返回 C 程序,同时退出 CMD.EXE 的辅助副本。would run a copy of the command shell (CMD.EXE), set the environment variable LIB, and return to the C program, exiting the secondary copy of CMD.EXE. 退出 CMD.EXE 的副本将移除临时环境变量 LIB。Exiting that copy of CMD.EXE removes the temporary environment variable LIB.

同样,仅保留 _putenv 函数所做的更改,直到该程序结束。Likewise, changes made by the _putenv function last only until the program ends.

另请参阅See Also

库函数 Library Functions
_putenv、_wputenv _putenv, _wputenv
getenv、_wgetenvgetenv, _wgetenv