Changeset 1965 in Sophya for trunk/Eval
- Timestamp:
- Apr 25, 2002, 1:05:56 AM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Eval/COS/tios.cc
r1060 r1965 9 9 void twrite(ostream* s); 10 10 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 11 25 int main(int narg, char ** arg) 12 26 { … … 14 28 cout << "Usage: tios w/r/r2 \n" 15 29 << " 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; 18 32 exit(0); 19 33 } … … 71 85 72 86 cout << " ----- 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; 87 for(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 } 81 96 s->seekg((sizeof(int)+sizeof(float)+sizeof(double)), ios::beg); 82 97 pos = s->tellg(); … … 84 99 s->read((char *)(&fv), sizeof(float)); 85 100 s->read((char *)(&dv), sizeof(double)); 86 i = 1; 87 cout << "Seek-tread2 " << i << " IV= " << iv << " FV= " << fv << " DV= " << dv 101 cout << "Seek-tread-begin " << " IV= " << iv << " FV= " << fv << " DV= " << dv 88 102 << " Pos= " << pos << endl; 89 103 … … 97 111 double dv; 98 112 long pos; 99 for(i=0; i< 7; i++) {113 for(i=0; i<10; i++) { 100 114 pos = s->tellg(); 101 115 s->read((char *)(&iv), sizeof(int)); … … 107 121 108 122 cout << " ----- Check Output from here ------- " << endl; 123 for(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 109 134 s->seekg(0, ios::end); 110 135 pos = s->tellg(); … … 118 143 s->read((char *)(&dv), sizeof(double)); 119 144 i = 9; 120 cout << "Seek-tread2 " << i<< " IV= " << iv << " FV= " << fv << " DV= " << dv145 cout << "Seek-tread2-begin " << " IV= " << iv << " FV= " << fv << " DV= " << dv 121 146 << " Pos= " << pos << endl; 122 147 123 148 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= " << fv132 << " DV= " << dv << " Pos= " << pos << endl;133 }134 149 }
Note:
See TracChangeset
for help on using the changeset viewer.