首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

前辈们进来看看为什么有错解决方案

2012-03-02 
前辈们进来看看为什么有错//library_manager.cpp:定义控制台应用程序的入口点。//#includestdafx.h #incl

前辈们进来看看为什么有错
//   library_manager.cpp   :   定义控制台应用程序的入口点。
//

#include   "stdafx.h "
#include "iostream "
#include <string>
#include <utility>  
#include <vector>
#include <fstream> //文件输入输出的时候一定要包含这个头文件
using   namespace   std;
//注意使用pair时不是包含#include <pair> ,而是包含#include <utility> .

string   s1= "d:\\book.bat ";     //开始的时候老是文件打开失败,我把“d:\book.bat "改成
string   s2= "d:\\reader.bat ";// "d:\\book.bat "竟然就好了
        fstream   file_book;
fstream   file_reader;

void   input_reader();//对input_reader()函数的声明
class   reader
{
public:
reader()
{
cout < < "reader的构造函数被调用 " < <endl;
}
~reader()
{
cout < < "reader的析构函数被调用 " < <endl;
}

friend   void   input_reader();//对友元函数的声明
private:
string   readername;//读者姓名
int         number;         //借阅证编号
pair <string,string>   borrowbook;//所借阅的书的名称和编号  
};

void   input_newbook();//对input_newbook()函数的声明
class   book
{
public:
book()
{
cout < < "book的构造函数被调用 " < <endl;
}

~book()
{
cout < < "book的析构函数被调用 " < <endl;
}


friend   void   input_newbook();//对友元的声明

private:
string     bookname;     //书的名字
        stringauthor;         //书的作者      
int           edition;       //书的版本
string   press;             //书的作者
double   price;             //书的价格
        vector <string>   numbers_of_allcopys;//所有的这本书的编号
vector <string>   numbers_of_nowcopys;//在馆的这本书的编号
static   int   count;//记录有多少种书。
};
int   book::count   =0;     //书的种数初始化为0;

void   input_newbook()
{        
double   jiage;
int   banbenhao;
bool   tag=false;//用来表示是否在书库中找到这个书名
  book     book1,book2;
string   s3,s4,s5,s6;
cout < < "请输入所要添加的新书的名字 " < <endl;
cin> > s3;
cout < < "请输入所要添加的新书的作者 " < <endl;
cin> > s4;
cout < < "请输入所要添加的新书的出版社 " < <endl;
cin> > s5;
        cout < < "请输入所要添加的新书的版本号 " < <endl;
cin> > banbenhao;
  //只有书名,作者,出版社,版本号都一样才能确定是同一本书的copy
file_book.open(s1.c_str   (),ios_base::in|ios_base::out     );//同时以读和写模式打开文件
if(book::count)
{


while(file_book> > book1)
//这个地方编译器提示:
没有找到接受“book”类型的右操作数的运算符(或没有可接受的转换)
少一个“)”和“;”
试图匹配参数列表“(std::fstream,   book)”时
d:\library_manager\library_manager.cpp(86)   :   fatal   error   C1903:   无法从以前的错误中恢复;正在停止编译


{
if(book1.bookname   ==s3&&book1.author==s4&&book1.press   ==s5&&book1.edition   ==banbenhao   )
{    
tag=true;
break;
}
}
}//外if结束


if(tag==true)
{
cout < < "这个书名以及存在,请输入新的书的编号 " < <endl;


cin> > s6;
book1.numbers_of_allcopys   .push_back   (s4);
book1.numbers_of_nowcopys   .push_back   (s4);
}
else
{
cout < < "\n这个书名在书库中不存在\n " < < "请输入书的编号 " < <endl;
cin> > s6;
cout < < "请输入这本书的价格 " < <endl;
cin> > jiage;
book2.author   =s4;
book2.bookname   =s3;
book2.edition   =banbenhao;
book2.numbers_of_allcopys   .push_back   (s6);
book2.numbers_of_nowcopys   .push_back   (s6);
book2.press   =s5;
book2.price   =jiage;
++book2.count   ;//增加书的种数
}


}

void   input_reader()
{       static   int   auto_fenhao=1;//用来依次给借阅证编号
bool   tag=false;
reader   reader1;
reader   reader2;
string   s1;
cout < < "请输入你的姓名 " < <endl;
cin> > s1;
        file_reader.open(s1.c_str   (),ios_base::in|ios_base::out     );//同时以读和写模式打开文件


while(file_reader> > reader1)
//这个地方也是相同的提示,估计是同一个问题


if(reader1.readername   ==s1)
{
cout < < "你已经有了一个借阅证,一个人只可以办理一个借阅证 " < <endl;
return;     //如果已经有了一个借阅证,退出
}
}
reader2.readername=s1;
reader2.number=auto_fenhao++;
//后面还有将reader2存入file_reader的操作没有完成
}
       


 
void   menu()
{      
int   xuanze;
cout < < "*******************************选择菜单********************************** " < <endl;
cout < < "                                                               1.新书入库                                                                 " < <endl;
cout < < "                                                               2.新办图书证                                                             " < <endl;
cout < < "                                                               3.借书                                                                         " < <endl;
cout < < "                                                               4.还书                                                                         " < <endl;


cout < < "                                                               5.退出系统                                                                 " < <endl;
cout < < "*******************************请按键选择******************************** " < <endl;
cin> > xuanze;
while(xuanze> 5   ||xuanze <1)
{
cout < < "没有这个选项,请重新选择 " < <endl;
cin> > xuanze;
}
switch(xuanze)
{case   1:
              input_newbook();
      break;
      //后面还有其他的选项操作没有完成





}//switch的结束


       


}



[解决办法]

while(file_book> > book1)
//这个地方编译器提示:
没有找到接受“book”类型的右操作数的运算符(或没有可接受的转换)
少一个“)”和“;”
试图匹配参数列表“(std::fstream, book)”时
d:\library_manager\library_manager.cpp(86) : fatal error C1903: 无法从以前的错误中恢复;正在停止编译
=======================================
你要重载操作符 < < > > 呀
[解决办法]
book类没有定义> > 操作符

热点排行