免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2505 | 回复: 2
打印 上一主题 下一主题

vc下为什么不行?是库装得不全吗? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-03-11 13:40 |只看该作者 |倒序浏览
I am sure it's the problem of the platform, maybe configration of VC.
Because it's ok under linux and GCC.


#include <iostream>;
#include <algorithm>;
#include <vector>;
#include <iterator>;

int main()
{
      int ia[10]={ 34,91,83,56,29,93,56,12,88,72 };
      vector<int>; vec(ia,ia+10);

      vector<int>;::iterator presult;
      presult=min_element(vec.begin(),vec.end());
      cout << "The minimum is " << *presult << endl;
      cout << "The sequence number is " << presult-vec.begin() << endl;


********************************************
Under VC&amp;W2K

E:\CPP\72\72.cpp(13) : error C2065: 'vector' : undeclared identifier
E:\CPP\72\72.cpp(13) : error C2062: type 'int' unexpected
E:\CPP\72\72.cpp(15) : error C2062: type 'int' unexpected
E:\CPP\72\72.cpp(15) : error C2039: 'iterator' : is not a member of '`global
namespace''
E:\CPP\72\72.cpp(16) : error C2065: 'presult' : undeclared identifier
E:\CPP\72\72.cpp(16) : error C2065: 'min_element' : undeclared identifier
E:\CPP\72\72.cpp(16) : error C2065: 'vec' : undeclared identifier
E:\CPP\72\72.cpp(16) : error C2228: left of '.begin' must have
class/struct/union type
E:\CPP\72\72.cpp(16) : error C2228: left of '.end' must have
class/struct/union type
E:\CPP\72\72.cpp(17) : error C2065: 'cout' : undeclared identifier
E:\CPP\72\72.cpp(17) : error C2100: illegal indirection
E:\CPP\72\72.cpp(17) : error C2065: 'endl' : undeclared identifier
E:\CPP\72\72.cpp(17) : warning C4552: '<<' : operator has no effect;
expected operator with side-effect
E:\CPP\72\72.cpp(19) : warning C4508: 'main' : function should return a
value; 'void' return type assumed
Error executing cl.exe.

72.exe - 12 error(s), 2 warning(s)


*********************************************
Under linux and GCC, the output is:

The minimun number is 12
The sequence number of the min is 8

论坛徽章:
0
2 [报告]
发表于 2003-03-11 15:20 |只看该作者

vc下为什么不行?是库装得不全吗?

加了 using namespace std;
问题就解决了。

请问在本练习中,namespace起什么作用?为什么要加namespace呢?

论坛徽章:
0
3 [报告]
发表于 2003-03-11 17:50 |只看该作者

vc下为什么不行?是库装得不全吗?

namespace 是c++新加的关键字

表示名字空间
加入理由是为了防止随着程序的过大而发生名字冲突问题


加了namespace 后
标准C++的类都饮食在std名字空间下
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP