CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C++ 语言

哪里出错了?

楼主WiseNeuro(春之舞)2004-12-04 18:10:23 在 C/C++ / C++ 语言 提问

有下面一段程序:  
  //---------------------------------------------------------------------------  
   
   
  #include   <vector>  
  #include   <iostream>  
  #include   <string>  
  #include   <list>    
   
  //---------------------------------------------------------------------------  
   
   
  struct   Entry{  
      string     bookname   ;  
      string     card   ;  
  };  
  void   f(vector<Entry>&   ve,   list<Entry>&   le)  
  {  
      sort(ve.begin(),   ve.end())   ;  
      unique_copy(ve.begin(),   ve.end),   le.begin())   ;  
  }  
  void   f1(vector<Entry>&   ve,   list<Entry>&   le)  
  {  
    sort(ve.begin(),   ve.end)   ;  
    unique_copy(ve.begin(),   ve.end(),   back_insert(le))  
  }  
  int   main(int   argc,   char*   argv[])  
  {  
                  vector<Entry>   &vbook   ;  
                  list<Entry>&   &lbook   ;  
                  f(vbook,   lbook)   ;  
   
   
                  return   0;  
  }  
  //---------------------------------------------------------------------------  
  在vc6种编译时除下面错误:  
  aglor1.cpp  
  G:\exise\aglor1.cpp(13)   :   error   C2146:   syntax   error   :   missing   ';'   before   identifier   'bookname'  
  G:\exise\aglor1.cpp(13)   :   error   C2501:   'string'   :   missing   storage-class   or   type   specifiers  
  G:\exise\aglor1.cpp(13)   :   error   C2501:   'bookname'   :   missing   storage-class   or   type   specifiers  
  G:\exise\aglor1.cpp(14)   :   error   C2146:   syntax   error   :   missing   ';'   before   identifier   'card'  
  G:\exise\aglor1.cpp(14)   :   error   C2501:   'string'   :   missing   storage-class   or   type   specifiers  
  G:\exise\aglor1.cpp(14)   :   error   C2501:   'card'   :   missing   storage-class   or   type   specifiers  
  G:\exise\aglor1.cpp(16)   :   error   C2065:   'vector'   :   undeclared   identifier  
  G:\exise\aglor1.cpp(16)   :   error   C2275:   'Entry'   :   illegal   use   of   this   type   as   an   expression  
                  G:\exise\aglor1.cpp(12)   :   see   declaration   of   'Entry'  
  G:\exise\aglor1.cpp(16)   :   error   C2065:   've'   :   undeclared   identifier  
  G:\exise\aglor1.cpp(16)   :   error   C2065:   'list'   :   undeclared   identifier  
  G:\exise\aglor1.cpp(16)   :   error   C2275:   'Entry'   :   illegal   use   of   this   type   as   an   expression  
                  G:\exise\aglor1.cpp(12)   :   see   declaration   of   'Entry'  
  G:\exise\aglor1.cpp(16)   :   error   C2065:   'le'   :   undeclared   identifier  
  G:\exise\aglor1.cpp(17)   :   error   C2448:   '<Unknown>'   :   function-style   initializer   appears   to   be   a   function   definition  
  G:\exise\aglor1.cpp(21)   :   error   C2275:   'Entry'   :   illegal   use   of   this   type   as   an   expression  
                  G:\exise\aglor1.cpp(12)   :   see   declaration   of   'Entry'  
  G:\exise\aglor1.cpp(21)   :   error   C2275:   'Entry'   :   illegal   use   of   this   type   as   an   expression  
                  G:\exise\aglor1.cpp(12)   :   see   declaration   of   'Entry'  
  G:\exise\aglor1.cpp(22)   :   error   C2448:   '<Unknown>'   :   function-style   initializer   appears   to   be   a   function   definition  
  G:\exise\aglor1.cpp(28)   :   error   C2275:   'Entry'   :   illegal   use   of   this   type   as   an   expression  
                  G:\exise\aglor1.cpp(12)   :   see   declaration   of   'Entry'  
  G:\exise\aglor1.cpp(28)   :   error   C2065:   'vbook'   :   undeclared   identifier  
  G:\exise\aglor1.cpp(29)   :   error   C2275:   'Entry'   :   illegal   use   of   this   type   as   an   expression  
                  G:\exise\aglor1.cpp(12)   :   see   declaration   of   'Entry'  
  G:\exise\aglor1.cpp(29)   :   error   C2065:   'lbook'   :   undeclared   identifier  
  G:\exise\aglor1.cpp(29)   :   error   C2102:   '&'   requires   l-value  
  G:\exise\aglor1.cpp(30)   :   error   C2065:   'f'   :   undeclared   identifier  
  Error   executing   cl.exe.  
   
  aglor1.obj   -   22   error(s),   0   warning(s)  
  //____________________________________  
  请问错再哪了? 问题点数:20、回复次数:12Top

1 楼Flood1984(峰子)回复于 2004-12-04 18:37:44 得分 4

在  
  #include   <vector>  
  #include   <iostream>  
  #include   <string>  
  #include   <list>    
   
  后加上一句:  
  using   namespace   std;Top

2 楼oyljerry(【勇敢的心】→ ㊣提拉米苏√㊣)回复于 2004-12-04 18:52:05 得分 3

加上namespace  
    sort(ve.begin(),   ve.end)   ;  
  -》   sort(ve.begin(),   ve.end())   ;  
   
  变量定义不需要引用Top

3 楼greenteanet(扎扎实实打基础,保持一颗平常心。)回复于 2004-12-04 19:05:03 得分 3

//---------------------------------------------------------------------------  
   
  #include   <vector>  
  #include   <iostream>  
  #include   <string>  
  #include   <list>    
  using   namespace   std;  
   
  //---------------------------------------------------------------------------  
   
   
  struct   Entry  
  {  
      string     bookname   ;  
      string     card   ;  
  };  
  void   f(vector<Entry>&   ve,   list<Entry>&   le)  
  {  
      sort(ve.begin(),   ve.end())   ;  
      unique_copy(ve.begin(),   ve.end(),   le.begin())   ;  
  }  
  void   f1(vector<Entry>&   ve,   list<Entry>&   le)  
  {  
    sort(ve.begin(),   ve.end)   ;  
    unique_copy(ve.begin(),   ve.end(),   back_insert(le));  
  }  
  int   main()  
  {  
                  vector   <Entry>   &vbook   ;  
                  list   <Entry>&   lbook   ;  
                  f(vbook,   lbook)   ;  
   
   
                  return   0;  
  }  
  //---------------------------------------------------------------------------Top

4 楼WiseNeuro(春之舞)回复于 2004-12-04 21:57:41 得分 0

谢谢大家:)  
  现在程序变成这样了:  
  //---------------------------------------------------------------------------  
   
   
  #include   <iostream>  
  #include   <string>  
  #include   <vector>  
  #include   <list>  
  #pragma   hdrstop  
   
  //---------------------------------------------------------------------------  
   
  //#pragma   argsused  
  using   namespace   std   ;  
  struct   Entry{  
      string   name   ;  
      string   number   ;  
  };  
   
  void   f(vector<Entry>&   ve,   list<Entry>&   le)  
  {  
      sort(ve.begin(),   ve.end())   ;  
      unique_copy(ve.begin(),   ve.end(),   le.begin())   ;  
  }  
  void   f1(vector<Entry>&   ve,   list<Entry>&   le)  
  {  
    sort(ve.begin(),   ve.end())   ;  
    unique_copy(ve.begin(),   ve.end(),   back_inserter(le))   ;  
  }  
  int   main(int   argc,   char*   argv[])  
  {  
                  vector<Entry>   &vbook   ;  
                  list<Entry>&   lbook   ;  
   
                  f(vbook,   lbook)   ;  
   
   
                  return   0;  
  }  
  //---------------------------------------------------------------------------  
  编译错误为:  
  Compiling...  
  aglor1.cpp  
  G:\exise\aglor1.cpp(21)   :   error   C2065:   'sort'   :   undeclared   identifier  
  G:\exise\aglor1.cpp(22)   :   error   C2065:   'unique_copy'   :   undeclared   identifier  
  G:\exise\aglor1.cpp(31)   :   error   C2530:   'vbook'   :   references   must   be   initialized  
  G:\exise\aglor1.cpp(32)   :   error   C2530:   'lbook'   :   references   must   be   initialized  
  Error   executing   cl.exe.  
   
  aglor1.obj   -   4   error(s),   0   warning(s)  
  //——————————————————————————————  
   
  我还应该改哪里?谢谢。  
  Top

5 楼WiseNeuro(春之舞)回复于 2004-12-05 13:08:01 得分 0

我添加了两个头文件#include   <algorithm>,#include   <functional>  
  //---------------------------------------------------------------------------  
   
   
  #include   <iostream>  
  #include   <string>  
  #include   <vector>  
  #include   <list>  
  #include   <algorithm>  
  #include   <functional>  
   
  #pragma   hdrstop  
   
  //---------------------------------------------------------------------------  
   
  //#pragma   argsused  
  using   namespace   std   ;  
  struct   Entry{  
      string   name   ;  
      string   number   ;  
  };  
   
  void   f(vector<Entry>&   ve,   list<Entry>&   le)  
  {  
      sort(ve.begin(),   ve.end())   ;  
      unique_copy(ve.begin(),   ve.end(),   le.begin())   ;  
  }  
  void   f1(vector<Entry>&   ve,   list<Entry>&   le)  
  {  
    sort(ve.begin(),   ve.end())   ;  
    unique_copy(ve.begin(),   ve.end(),   back_inserter(le))   ;  
  }  
  int   main(int   argc,   char*   argv[])  
  {  
                  vector<Entry>   &vbook;  
                  list<Entry>   &lbook   ;  
  //copy()  
                  f(vbook,   lbook)   ;  
   
   
                  return   0;  
  }  
  //---------------------------------------------------------------------------  
  编译错误为:  
  aglor1.cpp  
  G:\exise\aglor1.cpp(34)   :   error   C2530:   'vbook'   :   references   must   be   initialized  
  G:\exise\aglor1.cpp(35)   :   error   C2530:   'lbook'   :   references   must   be   initialized  
  Error   executing   cl.exe.  
   
  aglor1.obj   -   2   error(s),   0   warning(s)Top

6 楼avalonBBS("︶.︶メ)→( ̄ε ̄メ)回复于 2004-12-05 13:14:30 得分 3

vector<Entry>   &vbook;  
                  list<Entry>   &lbook   ;  
  引用要初始化Top

7 楼avalonBBS("︶.︶メ)→( ̄ε ̄メ)回复于 2004-12-05 13:14:59 得分 2

vector<Entry>   vbook;  
                  list<Entry>   lbook   ;  
  这样就行了Top

8 楼WiseNeuro(春之舞)回复于 2004-12-05 19:05:00 得分 0

改成  
  vector<Entry>   vbook;  
  list<Entry>   lbook   ;  
  后错误更多了。关键是如何初始化vbook和lbook   。Top

9 楼tlzhu()回复于 2004-12-05 19:44:18 得分 1

初始化就往里添加Entry结构的数据啊。Top

10 楼WiseNeuro(春之舞)回复于 2004-12-05 22:57:48 得分 0

该怎样添加数据呢?可不可以告诉我具体代码?Top

11 楼libbyliugang()回复于 2004-12-06 19:19:15 得分 2

#include   <iostream>   是C++标准形式  
  但是,要使用它必须包含:  
  using   namespace   std;  
  因为,许多东西都在std命名空间中声明的Top

12 楼rexking0(风之彩)回复于 2004-12-06 20:51:40 得分 2

#include   <iostream>   是一种标准输入流  
  用cin时   可这样使用std::cin   但每次都要加上std::  
  也可在先using     std::cin   那以后可直接用cin    
  补充一下libbyliugang的话语  
  小程序可使用using   namespace   std;但大程序也这样用那可能会造成名字冲突Top

相关问题

  • 哪里出错了
  • 到底哪里出错了?
  • 到底出错在哪里???????
  • 急!哪里出错啊,
  • 这个哪里出错了?
  • 哪里出错了呢???
  • 哪里出错了?求教!
  • 这段JAVA程序哪里出错阿?
  • 分页程序哪里出错了?
  • 安装时哪里出错了?

关键词

  • cpp
  • vector
  • storage
  • aglor1
  • exise
  • lbook
  • vbook
  • ve
  • le
  • identifierg

得分解答快速导航

  • 帖主:WiseNeuro
  • Flood1984
  • oyljerry
  • greenteanet
  • avalonBBS
  • avalonBBS
  • tlzhu
  • libbyliugang
  • rexking0

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo