| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 435 人关注过本帖
标题:运行时输出出错,请问原因。
只看楼主 加入收藏
hsnr
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2010-4-4
结帖率:90.32%
收藏
 问题点数:0 回复次数:1 
运行时输出出错,请问原因。
编写了一个输入输出类,前面运行都没问题,但到了最后一个输入输出就中断,请问是什么原因?程序如下
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;
}
搜索更多相关主题的帖子: 输出 运行 
2010-04-22 13:44
hsnr
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2010-4-4
收藏
得分:0 
问题已解决。
2010-04-22 19:40
快速回复:运行时输出出错,请问原因。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038427 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved