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
- 从python回调到c++的选项 2022-11-16
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 静态初始化顺序失败 2022-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- C++ 协变模板 2021-01-01