以编程方式删除环境变量 [英] Remove environmental variable programmatically

查看:64
本文介绍了以编程方式删除环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为一些C ++代码编写一个单元测试,以检查环境变量的存在.我正在使用MSVS 2008和gtest作为我的框架.我使用putenv添加环境变量,使用getevn检查环境变量,但是我不知道如何删除它,因此其他任何测试都不会看到它.我意识到这可能很容易,但是我无法在互联网上找到答案.谢谢

I need to write a unit test for some C++ code that checks for the presence of an environmental variable. I'm using MSVS 2008 and gtest as my framework. I add the environmental variable using putenv, I check the environmental variable using getevn, but I can't figure out how to remove it so that no other test will see it. I realize this is probably easy, but I can't find the answer on the internet. Thanks

推荐答案

再次调用 putenv 指定"SOME_VAR =" 作为参数将删除环境变量 SOME_VAR .顺便说一句,由于不推荐使用 putenv ,Microsoft建议使用 _putenv .

Calling putenv again specifying "SOME_VAR=" as parameter will delete environment variable SOME_VAR. btw, Microsoft recommends using _putenv as putenv is deprecated.

这篇关于以编程方式删除环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆