Changeset 1965 in Sophya for trunk/Eval


Ignore:
Timestamp:
Apr 25, 2002, 1:05:56 AM (23 years ago)
Author:
ansari
Message:

amelioration du programme test/check seekg() sur iostream - Reza 25/4/2002

File:
1 edited

Legend:

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

    r1060 r1965  
    99void twrite(ostream* s);
    1010
     11// -----------------------------------------------------
     12// This test program illustrates the problem with g++
     13//  (pb with g++ 2.95 3.0)
     14// iostream library with seekg(..., ios::end)
     15// # compile the program
     16// csh> g++ -o tios tios.cc
     17// # Create the test data file tios.dat
     18// csh> ./tios w
     19// # Read with seekg(... ios::end) ---> wrong result
     20// csh> ./tios r
     21// # seekg(... ios::beg) works OK
     22// csh> ./tios r2
     23// ----------------------------------------------------
     24
    1125int main(int narg, char ** arg)
    1226{
     
    1428  cout << "Usage: tios w/r/r2 \n"
    1529       << "  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;
     30       << "  r  : Read data file with seekg(ios::end)  -> g++/Linux Pb \n"
     31       << "  r2 : Read  data file with seekg(ios::beg) g++/Linux OK \n" << endl;
    1832  exit(0);
    1933  }
     
    7185
    7286cout << " ----- Check Output from here ------- " << endl;
    73 s->seekg(-(sizeof(int)+sizeof(float)+sizeof(double)), ios::end);
    74 pos = s->tellg();
    75 s->read((char *)(&iv), sizeof(int));
    76 s->read((char *)(&fv), sizeof(float));
    77 s->read((char *)(&dv), sizeof(double));
    78 i = 9;
    79 cout << "Seek-tread " << i << " IV= " << iv << " FV= " << fv << " DV= " << dv
    80      << " Pos= " << pos << endl;
     87for(i=0; i<4; i++) {
     88  s->seekg(-i*(sizeof(int)+sizeof(float)+sizeof(double)), ios::end);
     89  pos = s->tellg();
     90  s->read((char *)(&iv), sizeof(int));
     91  s->read((char *)(&fv), sizeof(float));
     92  s->read((char *)(&dv), sizeof(double));
     93  cout << "Seek-tread-end " << " IV= " << iv << " FV= " << fv << " DV= " << dv
     94       << " Pos= " << pos << endl;
     95}
    8196s->seekg((sizeof(int)+sizeof(float)+sizeof(double)), ios::beg);
    8297pos = s->tellg();
     
    8499s->read((char *)(&fv), sizeof(float));
    85100s->read((char *)(&dv), sizeof(double));
    86 i = 1;
    87 cout << "Seek-tread2 " << i << " IV= " << iv << " FV= " << fv << " DV= " << dv
     101cout << "Seek-tread-begin " << " IV= " << iv << " FV= " << fv << " DV= " << dv
    88102     << " Pos= " << pos << endl;
    89103
     
    97111double dv;
    98112long pos;
    99 for(i=0; i<7; i++) {
     113for(i=0; i<10; i++) {
    100114  pos = s->tellg();
    101115  s->read((char *)(&iv), sizeof(int));
     
    107121
    108122cout << " ----- Check Output from here ------- " << endl;
     123for(i=1; i<5; i+=2) {
     124  s->seekg(i*(sizeof(int)+sizeof(float)+sizeof(double)), ios::beg);
     125  pos = s->tellg();
     126  s->read((char *)(&iv), sizeof(int));
     127  s->read((char *)(&fv), sizeof(float));
     128  s->read((char *)(&dv), sizeof(double));
     129 
     130  cout << "Seek-tread2-begin " << " IV= " << iv << " FV= " << fv
     131       << " DV= " << dv << " Pos= " << pos << endl;
     132 }
     133
    109134s->seekg(0, ios::end);
    110135pos = s->tellg();
     
    118143s->read((char *)(&dv), sizeof(double));
    119144i = 9;
    120 cout << "Seek-tread2 " << i << " IV= " << iv << " FV= " << fv << " DV= " << dv
     145cout << "Seek-tread2-begin " << " IV= " << iv << " FV= " << fv << " DV= " << dv
    121146     << " Pos= " << pos << endl;
    122147
    123148
    124 s->seekg((sizeof(int)+sizeof(float)+sizeof(double)), ios::beg);
    125 for(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  }
    134149}
Note: See TracChangeset for help on using the changeset viewer.