关于VC6.0中的C++有关using语句的问题

allen6876 2009-10-30 06:34:40
事情是这个样子的,程序

#include <iostream>
#include <string>
#include <list>

//using namespace std;
using std::cout;
using std::endl;
using std::string;
using std::list;


int main()
{
list<int> iList;
for(int i = 0; i<10; i++)
{
iList.push_back(i);
}

for(list<int>::const_iterator citer = iList.begin();citer != iList.end(); citer++)
{
cout << *citer << "\t";
}

cout << endl;
return 0;
}

在dev-cpp(gcc)下编译通过,可是到了vc6.0下面,却出错,错误信息如下:

--------------------Configuration: vc_temp - Win32 Debug--------------------
Compiling...
main_vc.cpp
E:\WorkSpace\C++\Prj\vc_temp\main_vc.cpp(38) : error C2653: 'list<int,class std::allocator<int> >' : is not a class or namespace name
E:\WorkSpace\C++\Prj\vc_temp\main_vc.cpp(38) : error C2065: 'const_iterator' : undeclared identifier
E:\WorkSpace\C++\Prj\vc_temp\main_vc.cpp(38) : error C2146: syntax error : missing ';' before identifier 'citer'
E:\WorkSpace\C++\Prj\vc_temp\main_vc.cpp(38) : error C2065: 'citer' : undeclared identifier
E:\WorkSpace\C++\Prj\vc_temp\main_vc.cpp(38) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'class std::list<int,class std::allocator<int> >::iterator' (or there is no acceptable conversion)
E:\WorkSpace\C++\Prj\vc_temp\main_vc.cpp(38) : error C2677: binary '!=' : no global operator defined which takes type 'class std::list<int,class std::allocator<int> >::iterator' (or there is no acceptable conversion)
E:\WorkSpace\C++\Prj\vc_temp\main_vc.cpp(38) : error C2146: syntax error : missing ')' before identifier 'citer'
E:\WorkSpace\C++\Prj\vc_temp\main_vc.cpp(38) : error C2059: syntax error : ';'
E:\WorkSpace\C++\Prj\vc_temp\main_vc.cpp(38) : error C2059: syntax error : ')'
E:\WorkSpace\C++\Prj\vc_temp\main_vc.cpp(39) : error C2143: syntax error : missing ';' before '{'
E:\WorkSpace\C++\Prj\vc_temp\main_vc.cpp(40) : error C2100: illegal indirection
Error executing xicl6.exe.

vc_temp.exe - 11 error(s), 0 warning(s)


后来试了试,如果在源文件开头添上using namespace std,vc能顺利编译运行!

小弟在这里问一下,为何?

因为在C++ Primer第四版中提到,要尽量少用using directive,而多用using declartion。

谢谢!
...全文
138 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
哈利路亚1874 2009-10-30
  • 打赏
  • 举报
回复
据我所知,vc6.0对标准库的支持好像是百分之六十几!而boland C++对标准C++的支持达到97%!不知道vs的高版本达到了什么程度!
jackyjkchen 2009-10-30
  • 打赏
  • 举报
回复
VC6的C++标准问题是老大难了,换VS2008
ryfdizuo 2009-10-30
  • 打赏
  • 举报
回复
换编译器吧!现在2010都有beta版了,
一般用vs2008
senr0816 2009-10-30
  • 打赏
  • 举报
回复
请远离VC6.0~
VC6.0对STL支持得不好,程序本身没有错误,我在CODE::BLOCK下运行正常

65,208

社区成员

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

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