如何在C++中设置环境变量?

  • 它们不需要在程序执行后保持不变
  • 它们只需要在当前流程中可见
  • 首选独立于平台,但对于我的问题,只需要在Win32/64上工作

谢谢

推荐答案

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.

C++相关问答推荐

AVX-512 BF 16:直接加载bf 16值,而不是从fp 32转换

为什么已经设置的值在C中被重置为for循环条件中的新值?

InetPton()函数无效的IP地址

显式地将值转换为它从函数返回的类型的含义是什么?

特定闪存扇区的内存别名

C:fopen是如何实现二进制模式和文本模式的?

是否所有C编译器在将浮点数转换为整型数时都会隐式删除小数?

如何在下面的C代码中正确管理内存?

为什么中断函数会以这种方式影响数组?

每次除以或乘以整数都会得到0.0000

C:在编译时构建和使用字符串文字的预处理器宏?

当b是无符号字符时,int a=(b<;<;2)>;>;2;和int a=b&;0x3F;之间有什么区别?

C语言中奇怪的输出打印数组

从CentOS 7到Raspberry PI 2B的交叉编译-无法让LIBC和System Include标头一起工作

C中的char**v*char[]

Tcl_GetDoubleFromObj在列表的迭代中是一个缺点

如何用用户输入的多个字符串填充数组?

变量的指针右对齐,函数的指针左对齐

C23 中是否有 __attribute__((nonnull)) 的等效项?

初始化动态分配的布尔二维数组的最佳方法是什么?