根据我在网上找到的所有文档,看我的代码似乎是正确的.我的IDE是MS Visual Studio Xpress 4 Windows桌面2012,它的编译器抛出了错误:
Error 1 error C3861: 'setenv': identifier not found e:\users\owner\documents\visual studio 2012\projects\project1\project1\source1.cpp 18 1 Project1.
帮我!!!
#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);}
};
Run Code Online (Sandbox Code Playgroud) c++ environment-variables setenv visual-c++ visual-studio-2012
首先披露:我不是一个C程序员.我正在尝试编译一组具有很多谱系的C和Fortran代码,使用Makefile生成工程计算的可执行文件.我在sgi Irix(6.5.30)上使用gcc 4.7.1.在编写主程序时,首先我收到关于'隐式声明函数'setenv'的警告.随后,在生成所有目标"o"文件后,编译以错误结束:
ld32:错误33:未解析的数据符号"setenv"
注释掉定义'setenv'的单行允许编译成功并生成可执行文件.然而,与setenv的关系对该计划至关重要.
这导致我编写测试代码并确认同样的问题:
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
int main()
{
setenv("FILE","/usr/bin/example.c",50);
printf("File = %s\n", getenv("FILE"));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
根据我在堆栈交换和其他网站上搜索时发现的所有建议,我尝试包括不同的标题
#define _POSIX_C_SOURCE
Run Code Online (Sandbox Code Playgroud)
和
#define _GNU_SOURCE
Run Code Online (Sandbox Code Playgroud)
在任何#define语句之前.我也试图与编制-std=c99,以及-D_XOPEN_SOURCE和-D_GNU_SOURCE没有运气.
我也尝试使用Irix的本机C编译器(cc和c99)编译测试程序,我得到了同样的错误:
未解决的文字符号'setenv'
有人可以帮助我在我的系统和/或环境变量中寻找其他什么来解决这个错误吗?