哪里出错了?

WiseNeuro 2004-12-04 06:10:23
有下面一段程序:
//---------------------------------------------------------------------------


#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)
//____________________________________
请问错再哪了?
...全文
221 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
rexking0 2004-12-06
  • 打赏
  • 举报
回复
#include <iostream> 是一种标准输入流
用cin时 可这样使用std::cin 但每次都要加上std::
也可在先using std::cin 那以后可直接用cin
补充一下libbyliugang的话语
小程序可使用using namespace std;但大程序也这样用那可能会造成名字冲突
libbyliugang 2004-12-06
  • 打赏
  • 举报
回复
#include <iostream> 是C++标准形式
但是,要使用它必须包含:
using namespace std;
因为,许多东西都在std命名空间中声明的
WiseNeuro 2004-12-05
  • 打赏
  • 举报
回复
该怎样添加数据呢?可不可以告诉我具体代码?
tlzhu 2004-12-05
  • 打赏
  • 举报
回复
初始化就往里添加Entry结构的数据啊。
WiseNeuro 2004-12-05
  • 打赏
  • 举报
回复
改成
vector<Entry> vbook;
list<Entry> lbook ;
后错误更多了。关键是如何初始化vbook和lbook 。
avalonBBS 2004-12-05
  • 打赏
  • 举报
回复
vector<Entry> vbook;
list<Entry> lbook ;
这样就行了
avalonBBS 2004-12-05
  • 打赏
  • 举报
回复
vector<Entry> &vbook;
list<Entry> &lbook ;
引用要初始化
WiseNeuro 2004-12-05
  • 打赏
  • 举报
回复
我添加了两个头文件#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)
WiseNeuro 2004-12-04
  • 打赏
  • 举报
回复
谢谢大家:)
现在程序变成这样了:
//---------------------------------------------------------------------------


#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)
//——————————————————————————————

我还应该改哪里?谢谢。
greenteanet 2004-12-04
  • 打赏
  • 举报
回复
//---------------------------------------------------------------------------

#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;
}
//---------------------------------------------------------------------------
oyljerry 2004-12-04
  • 打赏
  • 举报
回复
加上namespace
sort(ve.begin(), ve.end) ;
-》 sort(ve.begin(), ve.end()) ;

变量定义不需要引用
Flood1984 2004-12-04
  • 打赏
  • 举报
回复

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

后加上一句:
using namespace std;

64,670

社区成员

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

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