如何使用C/C++設置環境變量?
我用C設置環境變量
putenv()
,但之後我跑的代碼,環境變異沒有任何改變。
代碼:
#include <stdlib.h>
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char a[128];
char b[256];
char all[512];
cin>>a;
cin>>b;
cout<<'\n';
cout<<a<<'\n';
cout<<b<<'\n';
strcpy(all,a);
strcat(all,"=");
strcat(all,b);
cout<<all<<'\n';
cout<<putenv(all);
}
我試圖函數 「SETENV()」 之前,但錯誤信息:
錯誤: 'SETENV' 不是在這個範圍內聲明
我的操作系統是Windows 7的
IDE代碼::塊
http://msdn.microsoft.com/en-us/library/83zh4e6k%28v=vs.80%29.aspx「僅影響當前進程本地的環境;不能使用它們來修改命令級環境「。 – BLUEPIXY
這是一些非常奇怪的C代碼。也許你有這個問題混淆? –
給科迪格雷非常感謝我努力工作 – Ken