c++程序出现错误,为什么输入的每个信息的第一个字母总是不能保存在文件里面。。求助??
#include<iostream>usingnamespacestd;#include<fstream>voidmain(){charPBookBarCode[20];...
#include<iostream>
using namespace std;
#include<fstream>
void main()
{
char PBookBarCode[20];
char PBookName[20];
char PFirstAuthorName[20];
char POtherAuthorName[20];
char PBookType[20];
char PBookPosition[20];
char PPublishUnit[20];
char PPublishTime[20];
char PPrice[20];
cout<<"teacher input book"<<endl;
ofstream BookFile("book.txt",ios::out|ios::app);
cout<<"Please enter Book information:"<<endl;
cout<<"Book Tiaoxingma:"<<endl;
cin.ignore();
cin.getline(PBookBarCode,20);
BookFile<<PBookBarCode<<endl;
cout<<"Book Name:"<<endl;
cin.ignore();
cin.getline(PBookName,20);
BookFile<<PBookName<<endl;
cout<<"First Author Name:"<<endl;
cin.ignore();
cin.getline(PFirstAuthorName,20);
BookFile<<PFirstAuthorName<<endl;
cout<<"OtherAuthorName:"<<endl;
cin.ignore();
cin.getline(POtherAuthorName,20);
BookFile<<POtherAuthorName<<endl;
cout<<"Book sort code:"<<endl;
cin.ignore();
cin.getline(PBookType,20);
BookFile<<PBookType<<endl;
cout<<"Book position:"<<endl;
cin.ignore();
cin.getline(PBookPosition,20);
BookFile<<PBookPosition<<endl;
cout<<"publish Unit:"<<endl;
cin.ignore();
cin.getline(PPublishUnit,20);
BookFile<<PPublishUnit<<endl;
cout<<"publish time:"<<endl;
cin.ignore();
cin.getline(PPublishTime,20);
BookFile<<PPublishTime<<endl;
cout<<"price:"<<endl;
cin.ignore();
cin.getline(PPrice,20);
BookFile<<PPrice<<endl;
cout<<"input success!!!\n";
BookFile.close();
} 展开
using namespace std;
#include<fstream>
void main()
{
char PBookBarCode[20];
char PBookName[20];
char PFirstAuthorName[20];
char POtherAuthorName[20];
char PBookType[20];
char PBookPosition[20];
char PPublishUnit[20];
char PPublishTime[20];
char PPrice[20];
cout<<"teacher input book"<<endl;
ofstream BookFile("book.txt",ios::out|ios::app);
cout<<"Please enter Book information:"<<endl;
cout<<"Book Tiaoxingma:"<<endl;
cin.ignore();
cin.getline(PBookBarCode,20);
BookFile<<PBookBarCode<<endl;
cout<<"Book Name:"<<endl;
cin.ignore();
cin.getline(PBookName,20);
BookFile<<PBookName<<endl;
cout<<"First Author Name:"<<endl;
cin.ignore();
cin.getline(PFirstAuthorName,20);
BookFile<<PFirstAuthorName<<endl;
cout<<"OtherAuthorName:"<<endl;
cin.ignore();
cin.getline(POtherAuthorName,20);
BookFile<<POtherAuthorName<<endl;
cout<<"Book sort code:"<<endl;
cin.ignore();
cin.getline(PBookType,20);
BookFile<<PBookType<<endl;
cout<<"Book position:"<<endl;
cin.ignore();
cin.getline(PBookPosition,20);
BookFile<<PBookPosition<<endl;
cout<<"publish Unit:"<<endl;
cin.ignore();
cin.getline(PPublishUnit,20);
BookFile<<PPublishUnit<<endl;
cout<<"publish time:"<<endl;
cin.ignore();
cin.getline(PPublishTime,20);
BookFile<<PPublishTime<<endl;
cout<<"price:"<<endl;
cin.ignore();
cin.getline(PPrice,20);
BookFile<<PPrice<<endl;
cout<<"input success!!!\n";
BookFile.close();
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询