Changeset 1060 in Sophya


Ignore:
Timestamp:
Jul 11, 2000, 1:00:11 PM (25 years ago)
Author:
ansari
Message:

ajout contournement pb ifstream::seekg() pour Linux ds tios.cc - Reza 11/7/2000

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Eval/COS/tios.cc

    r1055 r1060  
    66
    77void tread(istream* s);
     8void tread2(istream* s);
    89void twrite(ostream* s);
    910
     
    1112{
    1213if (narg < 2) {
    13   cout << "Usage: tios r/w" << endl;
     14  cout << "Usage: tios w/r/r2 \n"
     15       << "  w  : Write data file tios.cc \n"
     16       << "  r  : Read data file with seekg(ios::end)  -> Linux Pb \n"
     17       << "  r2 : Read  data file with seekg(ios::beg) Linux OK (??) \n" << endl;
    1418  exit(0);
    1519  }
     
    2024// is = new ifstream("tios.dat", ios::in | ios::binary);
    2125 is = new ifstream("tios.dat", ios::in );
    22  tread(is);
     26 if ( arg[1][1] == '2') tread2(is);
     27 else tread(is);
    2328 delete is;
    2429 }
     
    6570  }
    6671
     72cout << " ----- Check Output from here ------- " << endl;
    6773s->seekg(-(sizeof(int)+sizeof(float)+sizeof(double)), ios::end);
    6874pos = s->tellg();
     
    8490}
    8591
     92void tread2(istream* s)
     93{
     94int i;
     95int iv;
     96float fv;
     97double dv;
     98long pos;
     99for(i=0; i<7; i++) {
     100  pos = s->tellg();
     101  s->read((char *)(&iv), sizeof(int));
     102  s->read((char *)(&fv), sizeof(float));
     103  s->read((char *)(&dv), sizeof(double));
     104  cout << "tread2 " << i << " IV= " << iv << " FV= " << fv << " DV= " << dv
     105       << " Pos= " << pos << endl;
     106  }
    86107
     108cout << " ----- Check Output from here ------- " << endl;
     109s->seekg(0, ios::end);
     110pos = s->tellg();
     111cout << "Seek-tread2 s->seekg(0, ios::end); Pos = " << pos ;
     112pos -= (sizeof(int)+sizeof(float)+sizeof(double));
     113cout << " ---> Pos= " << pos << endl;
     114s->seekg(pos, ios::beg);
     115pos = s->tellg();
     116s->read((char *)(&iv), sizeof(int));
     117s->read((char *)(&fv), sizeof(float));
     118s->read((char *)(&dv), sizeof(double));
     119i = 9;
     120cout << "Seek-tread2 " << i << " IV= " << iv << " FV= " << fv << " DV= " << dv
     121     << " Pos= " << pos << endl;
     122
     123
     124s->seekg((sizeof(int)+sizeof(float)+sizeof(double)), ios::beg);
     125for(i=1; i<3; i++) {
     126  pos = s->tellg();
     127  s->read((char *)(&iv), sizeof(int));
     128  s->read((char *)(&fv), sizeof(float));
     129  s->read((char *)(&dv), sizeof(double));
     130 
     131  cout << "Seek-tread2-2 " << i << " IV= " << iv << " FV= " << fv
     132       << " DV= " << dv << " Pos= " << pos << endl;
     133 }
     134}
Note: See TracChangeset for help on using the changeset viewer.