第一句就错了? using namespace std;

bugonline 2007-07-04 10:19:10
我是C++菜鸟,本是做c#,被公司硬拉来做C++

编译提示 error: name must be a namespace name
并指向语句 using namespace std;

-----------
特别提醒,我用的编译器是intel c++ compiler 10.0
如果用vc6.0 自带的编译器能编译通过的, 我不清楚为何 Intel C++ 认为这句错了,应该如何改正?
...全文
501 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
xlbdan 2007-07-04
  • 打赏
  • 举报
回复
using namespace std; 要放到所有的 include 语句之后,
晨星 2007-07-04
  • 打赏
  • 举报
回复
总之,名字空间“std”必须在之前定义过,之后才可以using它。
标准头文件都是定义在std名字空间之中的,因此include了之后都可以using。
星羽 2007-07-04
  • 打赏
  • 举报
回复
using namespace std; 要放到所有的 include 语句之后,

起码要放到 #include <iostream> 之后
yydrewdrew 2007-07-04
  • 打赏
  • 举报
回复
要先include包含进来
才能用它的名字空间std,
不包含起来怎么用呢。
wantieee 2007-07-04
  • 打赏
  • 举报
回复
c# 不也是也有namespace吗?
jixingzhong 2007-07-04
  • 打赏
  • 举报
回复
using namespace std;

放在 所有的 include 语句之后
dovelee 2007-07-04
  • 打赏
  • 举报
回复
// NicConf.cpp : Defines the entry point for the DLL application.



#include "stdafx.h"

#include "netcfgx.h"

#include "NicConf.h"

#include "iphlpapi.h"

#include <comdef.h>

#include "objbase.h"

#include "ntddndis.h"

#include "devioctl.h"

using namespace std;

BOOL APIENTRY DllMain( HANDLE hModule,

DWORD ul_reason_for_call,

LPVOID lpReserved

)
我啃 2007-07-04
  • 打赏
  • 举报
回复
把unsing namespace std;
放到所有include后面
这是一个习惯
bugonline 2007-07-04
  • 打赏
  • 举报
回复
我试了加 #include <iostream> 也同样的错误
bugonline 2007-07-04
  • 打赏
  • 举报
回复
这个文件的开头是这样的:
-------------------------
// NicConf.cpp : Defines the entry point for the DLL application.

using namespace std;

#include "stdafx.h"

#include "netcfgx.h"

#include "NicConf.h"

#include "iphlpapi.h"

#include <comdef.h>

#include "objbase.h"

#include "ntddndis.h"

#include "devioctl.h"



BOOL APIENTRY DllMain( HANDLE hModule,

DWORD ul_reason_for_call,

LPVOID lpReserved

)
xlbdan 2007-07-04
  • 打赏
  • 举报
回复
同楼上几位说的.

你要先包含头文件,如#include <iostream>

再using namespace std;

后一句是打开头文件iostream中的std名字空间的意思,你不包含头文件就写上using这句,它打开

谁呀?
星羽 2007-07-04
  • 打赏
  • 举报
回复
你要先 include 一个标准库的文件

比如

#include "iostream"

#include "vector"

#include "list"

......




using namespace std;


我啃 2007-07-04
  • 打赏
  • 举报
回复
VC语法散漫,可能ICC要求比较严
我啃 2007-07-04
  • 打赏
  • 举报
回复
#include <iostream>//包含一个标准库文件后

之后再using namespace std;
taodm 2007-07-04
  • 打赏
  • 举报
回复
贴出此文件开头的代码
bugonline 2007-07-04
  • 打赏
  • 举报
回复
晕倒,我把这句注释掉就好了!

用各位的方法都行不同,但谢谢各位!

64,642

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧