首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

大神指导~'putenv' was not declared in this scope

2013-06-26 
大神指点~'putenv' was not declared in this scope我在dev-C++中编译程序他报错putenv was n

大神指点~'putenv' was not declared in this scope
我在dev-C++中编译程序
他报错'putenv' was not declared in this scope
可是我有#include <stdlib.h>啊
这真心不懂了

求大神指点~
[解决办法]
试试 _putenv 呢.
[解决办法]
试试这个可行的例子:


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

extern char **environ;

int main(void)
{
   char *path, *ptr;
   int i = 0;
   /* get the current path environment */
   ptr = getenv("PATH");
   /* set up new path */
   path = malloc(strlen(ptr)+15);
   strcpy(path,"PATH=");
   strcat(path,ptr);
   strcat(path,";c://temp");
   /* replace the current path and display current environment */
   putenv(path);
   while (environ[i])
       printf("%s/n",environ[i++]);
   return 0;
}

[解决办法]
那奇怪了,你试试先用C编译,就是说源代码是.c的。

引用:
Quote: 引用:

试试这个可行的例子:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

extern char **environ;

int main(void)
{
   char *path, *ptr;
   int i = 0;
   /* get the current path environment */
   ptr = getenv("PATH");
   /* set up new path */
   path = malloc(strlen(ptr)+15);
   strcpy(path,"PATH=");
   strcat(path,ptr);
   strcat(path,";c://temp");
   /* replace the current path and display current environment */
   putenv(path);
   while (environ[i])
       printf("%s/n",environ[i++]);
   return 0;
}


报错啊
Compiler: MinGW GCC 4.7.2 32-bit
Executing g++.exe...
g++.exe "E:\zhushuai\pandora\SourceCode\pandora_agents\win32\Untitled1.cpp" -o "E:\zhushuai\pandora\SourceCode\pandora_agents\win32\Untitled1.exe"   -I"D:\Program Files (x86)\Dev-Cpp\MinGW32\include"  -L"D:\Program Files (x86)\Dev-Cpp\MinGW32\lib" -static-libstdc++ -static-libgcc
E:\zhushuai\pandora\SourceCode\pandora_agents\win32\Untitled1.cpp: In function 'int main()':
E:\zhushuai\pandora\SourceCode\pandora_agents\win32\Untitled1.cpp:10:33: error: invalid conversion from 'void*' to 'char*' [-fpermissive]



Execution terminated


[解决办法]
_putenv
Creates new environment variables; modifies or removes existing ones.

int _putenv( const char *envstring );

Routine Required Header Compatibility 
_putenv <stdlib.h> Win 95, Win NT 



[解决办法]
你不要建C++的工程,建C的工程就好。

热点排行