This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: ofstream::seekp(0) does not work


 please post this to the list. We might as well start discussing this
now. It's my opinion that your code is incorrect: that seekp(0) does
not meet the restraints of seekp as defined in the standard.

Where seekp(pos) is undefined if pos is not the result of a previous
tellg or seekoff. It was my choice to enforce this: I know that Plum
Hall does not. 

-benjamin


On Wed, 22 Dec 1999 Bruno.Voigt@ic3s.de wrote:

> 
> Hello Benjamin,
> 
> here is a small sample:
> 
> bye, Bruno
> --
> Bruno.Voigt@ic3s.de  # IC3S AG # Tel. 04106.655.105 # Fax. 04106.4618
> ____________________ # Mobile 0700.686.00.686
> 
> /** testcase for ofstream::seekp().
>  *  expected content in test.dat: "Header2Record"
>  *  instead it contains: "Header1RecordHeader2"
>  *
>  *  Bruno.Voigt@ic3s.de / 22.12.1999
>  */
> #include <iostream>
> #include <iomanip>
> #include <fstream>
> #include <sstream>
> #include <string>
> #include <cstdlib>
> #include <ctime>
> using namespace std;
> 
> ofstream out;
> 
> 
> bool writeHeader1()
> {
>   out.seekp(0);
>   const char * header = "Header1";
>   out.write(header, strlen(header));
>   return true;
> }
> bool writeHeader2()
> {
>   out.seekp(0);
>   const char * header = "Header2";
>   out.write(header, strlen(header));
>   return true;
> }
> 
> bool writeRecord()
> {
>   const char * rec = "Record";
>   out.write(rec, strlen(rec));
>   return true;
> }
> 
> int main(int argc, char *argv[])
> {
>   out.open("test.dat", ios_base::out | ios_base::binary | ios_base::trunc);
>   if (!out.good()) {
>     cout << "cannot open outfile!" << endl;
>     exit(1);
>   }
>   writeHeader1();
>   writeRecord();
>   writeHeader2();
>   out.close();
>   return 0;
> }
> 
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]