大家帮我看看有什么问题!
也不知道什么原因 一个很简单的代码 但每次结果都会出现乱码问题 请高手指教!#include<iostream>
#include<fstream>
#include<string>
using namespace std;
class book
{
private:
int bookID;
string bookName;
string bookAuthor;
string bookPress;
float bookPrice;
public:
void get()
{
cout<<endl<<"输入书的编号"<<endl;
cin>>bookID;
cout<<endl<<"输入书的名字"<<endl;
cin.ignore();
cin>>bookName;
cout<<endl<<"输入书的作者"<<endl;
cin.ignore();
cin>>bookAuthor;
cout<<endl<<"输入书的出版社"<<endl;
cin.ignore();
cin>>bookPress;
cout<<endl<<"输入书的价钱"<<endl;
cin>>bookPrice;
}
void check()
{
cout<<endl<<"书的编号"<<endl;
cout<<bookID<<endl;
cout<<endl<<"书的名字"<<endl;
cout<<bookName<<endl;
cout<<endl<<"书的作者"<<endl;
cout<<bookAuthor<<endl;
cout<<endl<<"书的出版社"<<endl;
cout<<bookPress<<endl;
cout<<endl<<"书的价钱"<<endl;
cout<<bookPrice;
}
/*void flcheck(int)
{
ifstream ifile("F:\\book.dat");
int a;
string b;
string c;
string d;
float e;
ifile>>a>>b>>c>>d>>e;
int h;
cin>>h;
switch(h)
{
case 1:
cout<<"输入ID"<<endl;
cin>>a;
if(a==bookID)
{
cout<<bookName<<endl<<bookAuthor<<endl<<bookPress<<endl<<bookPrice<<endl;
break;
}
}
}*/
void idcheck(int q)
{
ifstream ifile("F:\\fa.dat");
int a;
string b;
string c;
string d;
float e;
ifile>>bookID>>bookName>>bookAuthor>>bookPress>>bookPrice;
if(q==bookID)
{
cout<<endl<<"查询结果:"<<endl<<bookID<<bookName<<bookAuthor<<bookPress<<bookPrice<<endl;
}
if(q!=bookID)
{
cout<<endl<<"查询结果:"<<endl<<"没有该书记录"<<endl;
}
}
};
int main()
{
int haha;
book FeinaAen;
while(1)
{
cout<<endl<<"0.退出"<<endl;
cout<<endl<<"1.插入书信息"<<endl;
cout<<endl<<"2.查看书信息"<<endl;
cout<<endl<<"3.删除书信息"<<endl;
cout<<endl<<"4.分类查找"<<endl;
cout<<endl<<"选择(0-4)"<<endl;
cin>>haha;
if(haha==1)
{
ofstream ofile("F:\\fa.dat",ios::app);
char reply='Y';
while(reply=='Y'||reply=='y')
{
cout<<endl<<"按以下提示输入"<<endl;
FeinaAen.get();
ofile.write((char *)&FeinaAen,sizeof(book));
cout<<endl<<"是否继续插入书信息[y/n][Y/N],按其他键退出程序"<<endl;
cin>>reply;
ofile.close();
}
if(reply=='N'||reply=='n')
continue;
if(reply!='N'||reply!='n'||reply!='y'||reply!='Y')
break;
//ofile.close();
}
if(haha==2)
{
ifstream ifile("F:\\fa.dat");
while(ifile)
{
FeinaAen.check();
ifile.read((char *)&FeinaAen,sizeof(book));
}
ifile.close();
}
if(haha==4)
{
int haha1;
cout<<endl<<"1.按ID查找"<<endl;
cout<<endl<<"2.按书名查找"<<endl;
cout<<endl<<"3.按作者查找"<<endl;
cout<<endl<<"4.按出版社查找"<<endl;
cin>>haha1;
if(haha1==1)
{
cout<<"输入ID"<<endl;
int u;
cin>>u;
FeinaAen.idcheck(u);
}
}
if(haha==0)
break;
}
return 0;
}
删除部分还没写 不用去看 查找方面不知道出了什么问题 我用链表形式写了一个同样的程序 就没有乱码情况 现在非常的不解!!
[[italic] 本帖最后由 Freeness 于 2007-11-25 17:52 编辑 [/italic]]