C++: Setenv(). Undefined identifier in Visual Studio(C++:Setenv().Visual Studio 中的未定义标识符)
问题描述
根据我可以在网上找到的所有文档,看我的代码似乎是正确的.我的 IDE 是 MS Visual Studio Xpress 4 Windows Desktop 2012,它的编译器抛出错误:
Error 1 error C3861: 'setenv': identifier not found e:usersownerdocumentsvisual studio 2012projectsproject1project1source1.cpp 18 1 Project1.>
帮帮我!!!
#include #include #include #include #include #include 使用命名空间标准;int howManyInClass = 0;int main(){long checklength = sizeof(getenv("classSize"))/sizeof(*getenv("classSize"));如果(校验长度== 0){cout<<"请输入您班级的学生人数";cin>howManyInClass;cin.ignore();setenv("classSize", howManyInClass, 1);}};      您可以使用 _putenv() 将字符串参数作为字符串classSize=7;
ostringstream classSize;类大小<<类大小="<<howManyInClass;_putenv(classSize.str().c_str());...或(最好)增强安全性 _putenv_s() 将键和值作为单独的 (const char*) 参数;
ostringstream classSize;类大小<Look my code seems to be correct, according to all the documentation I can find online. My IDE is MS Visual Studio Xpress 4 Windows Desktop 2012, and it's compiler is throwing up the error:
Error  1   error C3861: 'setenv': identifier not found e:usersownerdocumentsvisual studio 2012projectsproject1project1source1.cpp  18  1   Project1.
Help me!!!
#include <windows.h>
#include <sstream>
#include <ostream>
#include <cstdlib>
#include <iostream>
#include <stdlib.h>
using namespace std;
int howManyInClass = 0;
int main(){
long checklength = sizeof(getenv("classSize"))/sizeof(*getenv("classSize"));
if (checklength==0){
    cout<<"Please enter the ammount of students in your class";
    cin>> howManyInClass;
    cin.ignore();
    setenv("classSize", howManyInClass, 1);}
};
You can either use _putenv() which takes a string parameter as the string classSize=7;
ostringstream classSize;
classSize << "classSize=" << howManyInClass;
_putenv(classSize.str().c_str());
...or (preferably) the security enhanced _putenv_s() that takes the key and the value as separate (const char*) parameters;
ostringstream classSize;
classSize << howManyInClass;
_putenv_s("classSize", classSize.str().c_str());
这篇关于C++:Setenv().Visual Studio 中的未定义标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++:Setenv().Visual Studio 中的未定义标识符
 
				
         
 
            
        基础教程推荐
- 常量变量在标题中不起作用 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
    	 
						 
						 
						 
						 
						 
				 
				 
				 
				