运行时输出出错,请问原因。
编写了一个输入输出类,前面运行都没问题,但到了最后一个输入输出就中断,请问是什么原因?程序如下class DataBankbyInput
{
public:
DataBankbyInput( );
void InputBasic(int& NELEM,int& NPOIN,int& NDIME,int& NNODE,
int& Nx,int& Ny,double& Dtime,double& Ttime);
void InputBasicData(int** Lnods,double** Coord,double* InitialValue,double* dCbar);
~DataBankbyInput(){};
};
DataBankbyInput::DataBankbyInput( )
{
}
void DataBankbyInput::InputBasic(int& NELEM,int& NPOIN,int& NDIME,int& NNODE,
int& Nx,int& Ny,double& Dtime,double& Ttime)
{
ifstream inputfile;
string fname1;
cout<<"Enter the name of the FIRST input file"<<endl;
cin>>fname1;
inputfile.open(fname1.c_str());
if(inputfile.fail())
{
cout<<"The first file inputfile could not be opened"<<endl;
exit(2);
}
//
ofstream outputfile;
string fname0;
cout<<"Enter the name of the SECOND output file"<<endl;
cin>>fname0;
outputfile.open(fname0.c_str());
if(outputfile.fail())
{
cout<<"The second file outputfile could not be opened"<<endl;
exit(2);
}
// READ THE FIRST DATA CARD, AND ECHO IT IMMEDIATELY.
inputfile>>NELEM>>NPOIN>>NDIME>>NNODE>>Nx>>Ny;
outputfile<<"NELEM="<<NELEM<<" NPOIN="<<NPOIN<<" NDIME="<<NDIME<<" NNODE="<<NNODE<<" Nx="<<Nx<<" Ny="<<Ny<<endl;
// READ TIME STEPPING AND SELECTIVE OUTPUT PARAMETERS
inputfile>>Dtime>>Ttime;
outputfile<<"Dtime="<<Dtime<<" Ttime="<<Ttime<<endl;
return;
}
void DataBankbyInput::InputBasicData(int** Lnods,double** Coord,double* InitialValue,double* dCbar)
{
int ielem,inode,ipoin,idime,ithelm,ithpn,idCbar;
ifstream input_data_file;
string filename1;
cout<<"Enter the name of the 3rd input file"<<endl;
cin>>filename1;
input_data_file.open(filename1.c_str());
if(input_data_file.fail())
{
cout<<"The 3rd file input_data_file could not be opened"<<endl;
exit(2);
}
//
ofstream output_data_file;
string filename0;
cout<<"Enter the name of the fourth output file"<<endl;
cin>>filename0;
output_data_file.open(filename0.c_str());
if(output_data_file.fail())
{
cout<<"The fourth file output_data_file could not be opened"<<endl;
exit(2);
}
// READ THE FIRST DATA CARD, AND ECHO IT IMMEDIATELY.
for(ielem=0;ielem<NELEM;ielem++)
{
input_data_file>>ithelm;
output_data_file<<ithelm;
for(inode=0;inode<NNODE;inode++)
{
input_data_file>>Lnods[ielem][inode];
output_data_file<<Lnods[ielem][inode]<<endl;
}
}
for(ipoin=0;ipoin<NPOIN;ipoin++)
{
input_data_file>>ithpn;
output_data_file<<ithpn;
for(idime=0;idime<NDIME;idime++)
{
input_data_file>>Coord[ipoin][idime];
output_data_file<<Coord[ipoin][idime]<<endl;
}
}
for(ipoin=0;ipoin<NPOIN;ipoin++)
{
input_data_file>>ithpn>>InitialValue[ipoin];
output_data_file<<ithpn<<" "<<InitialValue[ipoin]<<endl;
}
for(ielem=0;ielem<NELEM;ielem++)
{
input_data_file>>idCbar>>dCbar[ielem];
cout<<"0"<<endl; //这个可以输出!
cout<<idCbar<<" "<<dCbar[ielem]<<endl; //到这里就出错了!!!!
output_data_file<<idCbar<<" "<<dCbar[ielem]<<endl;
}
return;
}