kündigen, genannt nach dem werfen einer Instanz von 'std::ios_base::failure' what(): basic

Bin ich etwa mit c++ und ich habe einige Probleme wenn ich will Lesen einer matrix aus einer Datei.
hier ist meine matrix in eine Datei:

0   0   0   0   0   0   0
0.0344828   0.323538    0.0108884   2.6302  -0.00601043     0.0019921   2.37015
0.0689655   0.315323    0.00207342  3.92065     -0.00923253     0.00402598  3.35243
0.103448    0.175781    -0.063686   4.23273     -0.00881114     0.0056472   3.79407
0.137931    0.0224418   -0.136528   4.29968     -0.00513587     0.00650649  4.04466
0.172414    -0.0932421  -0.183356   4.33218     -0.000438406    0.00697551  4.20336
0.206897    -0.148808   -0.193323   4.40354     0.00352467  0.00698478  4.31558
0.241379    -0.16686    -0.172197   4.51575     0.00628366  0.00647283  4.40149
0.275862    -0.164914   -0.129917   4.63925     0.00770706  0.00567122  4.46758
0.310345    -0.128657   -0.092887   4.73243     0.00787571  0.00482414  4.52067
0.344828    -0.0776035  -0.0664981  4.79118     0.00743055  0.00400328  4.56789
0.37931     -0.0385587  -0.05244    4.80834     0.0061065   0.00328682  4.60748
0.413793    -0.0040996  -0.0490464  4.79264     0.00462926  0.00260406  4.64237
0.448276    0.0220397   -0.0481575  4.76923     0.00303705  0.00194038  4.67413
0.482759    0.0398955   -0.0473876  4.7406  0.00182074  0.00128583  4.70189
0.517241    0.0541651   -0.0449     4.71528     0.000727833     0.000633435     4.72829
0.551724    0.0588831   -0.0362422  4.70938     8.49119e-05     -6.27609e-05    4.75152
0.586207    0.061897    -0.0272721  4.70866     -0.000363273    -0.000773489    4.77342
0.62069     0.0606852   -0.0129192  4.7187  -0.000587166    -0.00143652     4.79323
0.655172    0.0605354   -0.000346813    4.72946     -0.000544833    -0.00204383     4.81059
0.689655    0.0587716   0.0135411   4.73842     -0.0004949  -0.00264921     4.82794
0.724138    0.0639723   0.0221793   4.74228     -0.000198867    -0.0029033  4.84047
0.758621    0.0692056   0.0307559   4.746   9.95025e-05     -0.00315412     4.85295
0.793103    0.074144    0.037433    4.74651     0.000357403     -0.00325805     4.86406
0.827586    0.0841098   0.0399013   4.75459     0.000502533     -0.00296743     4.87154
0.862069    0.0937132   0.0425136   4.76246     0.000647458     -0.00267717     4.87901
0.896552    0.0997181   0.0454041   4.77419     0.000719785     -0.00227675     4.88509
0.931034    0.104461    0.0459297   4.79986     0.000615777     -0.00159462     4.88769
0.965517    0.109204    0.0464553   4.82552     0.000511769     -0.000912495    4.89028
1   0.112065    0.0491291   4.85342     0.00040813  -0.000228803    4.89288

und hier ist mein code:

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cmath>

using namespace std;

string fn, path_str;
string root("/home/mostafa/OpenFOAM/mostafa-2.1.0/run/tutorials/incompressible/pisoFoam/channelLES/Balaras/09/postProcessing/mydata/");
string endfile("/Data0_U_UMean.xy");
float fileName, h[30][95], u[30][95], v[30][95], w[30][95], data[7][30], uMean[7], vMean[30], wMean[30];
float uPrime[30][95], vPrime[30][95], wPrime[30][95];
float uPrime2Mean[30], vPrime2Mean[30], wPrime2Mean[30];
float uPrimeMean[30], vPrimeMean[30], wPrimeMean[30];
float u2_rms[30], v2_rms[30], w2_rms[30];



int main ()
{
    for (int t=0;t<96;t++)
    {
        fileName=769.999+t*10;
        string fn = static_cast<ostringstream*>( &(ostringstream() << fileName) )->str();
        path_str=root+ fn+endfile;
        const char* path=path_str.c_str();
        //myfile.open (path,ios::out);
        float data[7][30];

        ifstream myfile(path, fstream::in | fstream::out | fstream::binary);
        //ifstream myfile(path);

        if (!myfile)
        {
            cout << "Cannot open file.\n";
            return 0;
        }

        //Reading the data file
        for (int x = 0; x < 30; x++)
        {
            for (int y = 0; y < 7; y++)
            {
                myfile >> data[x][y];
                cout << data[x][y] << " ";
            }
            cout << "END OF ROW" <<endl;
        }

        myfile.close();

        //constructing h,u,v,w matrices
        for (int i=0; i<30; i++)
        {
            h[i][t]=data[i][0];
            u[i][t]=data[i][1];
            v[i][t]=data[i][2];
            w[i][t]=data[i][3];
            cout << w[i][t] << " ";
        }
        cout << "w[][]" << endl;
    }

    for (int i=0; i<30; i++)
    {
        for (int t=0; t<96; t++)
        {
            uMean[i]+=(u[i][t])/95;
            vMean[i]+=(v[i][t])/95;
            wMean[i]+=(w[i][t])/95;
        }
    }

    for (int i=0; i<30; i++)
    {
        for (int t=0; t<96; t++)
        {
            uPrime[i][t]=u[i][t]-uMean[i];
            vPrime[i][t]=v[i][t]-vMean[i];
            wPrime[i][t]=w[i][t]-wMean[i];
        }
    }

    for (int i=0; i<30; i++)
    {
        for (int t=0; t<96; t++)
        {
            uPrimeMean[i]+=(uPrime[i][t])/95;
            vPrimeMean[i]+=(vPrime[i][t])/95;
            wPrimeMean[i]+=(wPrime[i][t])/95;

            uPrime2Mean[i]+=pow(uPrime[i][t],2)/95;
            vPrime2Mean[i]+=pow(vPrime[i][t],2)/95;
            wPrime2Mean[i]+=pow(wPrime[i][t],2)/95;
/*
            uPrime2Mean_rms[i]+=pow(uPrime[i][t],2)/95/uMean[i];
            vPrime2Mean_rms[i]+=pow(vPrime[i][t],2)/95/vMean[i];
            wPrime2Mean_rms[i]+=pow(wPrime[i][t],2)/95/wMean[i];
            */
            u2_rms[i]=uPrime2Mean[i]/pow(uMean[i],2);
            v2_rms[i]=vPrime2Mean[i]/pow(vMean[i],2);
            w2_rms[i]=wPrime2Mean[i]/pow(wMean[i],2);
        }
    }
    /*
    ofstream Uf("home/mostafa/OpenFOAM/mostafa-2.1.0/run/tutorials/incompressible/pisoFoam/channelLES/Balaras/09/postProcessing/surfaceSampling2/Uf.xy");
    for (int i=0; i<30; i++)
    {
        myfile << h[i][1] <<"/t"<<
    }*/

    return 0;
}

und wenn ich es laufen lasse, liest es die Datei bis Zeile 12 und dann es gibt mir diese Fehlermeldung:

kündigen, genannt nach dem werfen einer Instanz von 'std::ios_base::failure' what(): basic_filebuf::Unterlauf Fehler beim Lesen der Datei

Ich check den code mit einer anderen Datei, welche den gleichen matrix-Dimensionen, aber verschiedene Nummern und es funktioniert einwandfrei!

jemand weiß, was ist das problem? und wo ist es?

Grüße,
Mostafa


danke für die Antwort

Ich denke, die kacke ist irgendwo in:

//Reading the data file
for (int x = 0; x < 30; x++)
{
    for (int y = 0; y < 7; y++)
    {
        myfile >> data[x][y];
        cout << data[x][y] << " ";
    }
    cout << "END OF ROW" <<endl;
}

und Sie sind zu Recht über die Grenzen.
Ich habe immer noch das problem

und wenn ich mit

string fn = std::to_string(fileName);

er sagt, dass "'to_string' ist nicht ein Mitglied von 'std'"

  • Warum, warum tun Sie static_cast<ostringstream*>( &(ostringstream() << fileName) )->str() ?!
  • das ist schon ein code-dump. Können Sie Sie reduzieren?
  • das ist erstaunlich! Ich Frage mich, ob die OP ein fuzzing-tool.
InformationsquelleAutor user246747 | 2014-08-22
Schreibe einen Kommentar