error C2677: binary '==' : no global operator 有关字符串的比较问题,球解答!

asuka__wei 2014-04-29 05:42:36
if(book[i].getname==name) 这行报错

error C2677: binary '==' : no global operator defined which takes type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there
is no acceptable conversion)

...全文
651 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
asuka__wei 2014-04-29
  • 打赏
  • 举报
回复
引用 3 楼 starytx 的回复:
getname后边要带 () ,那是一个方法
版主好快的速度啊 十分感谢
starytx 2014-04-29
  • 打赏
  • 举报
回复
getname后边要带 () ,那是一个方法
starytx 2014-04-29
  • 打赏
  • 举报
回复
双等号两边的分别是什么类型的对象?
asuka__wei 2014-04-29
  • 打赏
  • 举报
回复
#include <iostream> #include <iomanip> #include <string> using namespace std; class Reader { private: string Id; string Password; string Name; string Level; int Cap; public: int borbook[15]; string getname() { return Name; } string getid() { return Id; } string getpassword() { return Password; } string getlevel() { return Level; } int getcap() { return Cap; } void setReader(string id, string password, string name, string level, int cap) { Id=id; Password=password; Name=name; Level=level; Cap=cap; } void borrowbook(int bookid)//借书操作 { for(int i=0;i<Cap;i++) { if (borbook[i]==0) { borbook[i]=bookid; break; } } } int retbook(int bookid)//还书操作 { for(int i=0;i<Cap;i++) { if(borbook[i]==bookid) { borbook[i]=0; return 1; } } return 0; } Reader SearchReader(string id, string password) { cout<<"输入卡号:"<<endl; cin>>id; cout<<endl; cout<<"输入密码:"<<endl; cin>>password; cout<<endl; if (Id==id&&Password==password) { cout<<"姓名为:"<<Name<<endl; cout<<"借书等级为:"<<Level<<endl; cout<<"借书容量为:"<<Cap<<endl; cout << setw(5) << Id <<setw(10) << Name<<"借书编号:["; //setw( n ) 设域宽为n个字符 for(int i=0;i<Cap;i++) if(borbook[i]!=0) cout << borbook[i] << "|"; cout << "]"<<endl; } else cout<<"卡号或密码错位"<<endl; } }; class Book { public: string Id; string Name; string Author; string SearchId; int OnShelf; // 1:未借 2:已借 string getname() { return Name; } string getsearchid() { return SearchId; } string getauthor() { return Author; } void setBook(string id, string name, string author, string searchid) { Id=id; Name=name; Author=author; SearchId=searchid; OnShelf=1; } int borrowbook() //借书操作 { if (OnShelf==1) { OnShelf=0; return 1; } return 0; } void retbook() //还书操作 { OnShelf=1; } void disp() //输出图书 { cout << setw(6) << Id << setw(18) << Name << setw(10) <<(OnShelf==1? "在架":"已借") <<endl; } }; void main() { //数据 Reader reader[3]; reader[0].setReader("001","123","麦中凡","一",15); reader[1].setReader("002","2bk","张国锋","二",10); reader[2].setReader("003","318","杜杰","二",10); Book book[5]; book[0].setBook("001","高等数学","华罗庚","O13/10318"); book[1].setBook("002","高等数学","华罗庚","O13/10318"); book[2].setBook("003","高等数学","华罗庚","O13/10318"); book[3].setBook("004","高等数学","范颖川","O13/10437"); book[4].setBook("005","C++程序设计语言","Bjarne","TP312/10277"); char choice; int bookid,readerid; while(choice!='0') { cout <<endl<<endl<<"\t\t\t图书管理系统\n "; cout <<"1.借书\t2.还书\t3. 书名检索\4. 索书号检索\t5. 借书证信息"<<endl; cin >> choice; switch (choice) { case '1': { cout <<"借书\n读者编号:"; cin >>readerid; cout <<"图书编号:"; cin >>bookid; for(int i=0;i<3;i++) { if(i==readerid) { reader[i].borrowbook(bookid); cout<<"借书成功"<<endl; break; } } } break; case '2': { cout<<"还书\n读者编号:"; cin >>readerid; cout << "图书编号:"; cin >>bookid; for(int i=0;i<3;i++) { if(i==readerid) { reader[i].retbook(bookid); cout<<"还书成功"<<endl; break; } } } break; case '3': { string name; cout<<"输入书本名称;"<<endl; cin>>name; cout<<endl; for(int i=0;i<5;i++) { if(book[i].getname==name)这行有错啊 cout<<book[i].getname<<" "<<book[i].getauthor<<" "<<book[i].getsearchid<<endl; }} case '4': { string searchid; cout<<"输入索书号;"<<endl; cin>>searchid; cout<<endl; for(int i=0;i<5;i++) { if(book[i].getsearchid==searchid) cout<<book[i].getname<<" "<<book[i].getauthor<<" "<<book[i].getsearchid<<endl; }} case '5': { int id; string password; cout<<"输入卡号:"<<endl; cin>>id; cout<<endl; cout<<"输入密码:"<<endl; cin>>password; cout<<endl; for(int i=0;i<3;i++) { if (reader[i].getid==id&&reader[i].getpassword=password) { cout<<"姓名为:"<<reader[i].getname<<endl; cout<<"借书等级为:"<<reader[i].getlevel<<endl; cout<<"借书容量为:"<<reader[i].getcap<<endl; cout << setw(5) << Id <<setw(10) << Name<<"借书编号:["; //setw( n ) 设域宽为n个字符 for(int i=0;i<15;i++) if(reader[i].borbook[i]!=0) cout << borbook[i] << "|"; cout << "]"<<endl; break; } else cout<<"卡号或密码错位"<<endl; }} default:cout<<"输入错误,请从新输入:"; } } } 这是全部代码

65,207

社区成员

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

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