CPB Mailing List

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[BCB3] STL fstream program




Hello to all,
I have tested a STL sample form examples\stdlib\fstream.cpp. 
The output is wrong. The seekg() can't point to the correct position.
Why ?
I have simplified the program below.
//
// modified from /examples/stdlib/fstream.cpp
//
#include<iostream>
#include<fstream>
#ifndef _RWSTD_NO_NAMESPACE
  using namespace std;
#endif
int main ( )
{
  // create a bi-directional fstream object
  fstream inout("fstream.out");
  // output characters
  inout << "11111111111111111111\n";
  inout << "22222222222222222222\n";
  inout << "33333333333333333333\n";
  char p[100];
  inout.seekg(0);
  inout.getline(p,100);
  fstream::pos_type pos = inout.tellg();
  inout.seekp(pos);
  // replace the second line
  inout << "44444444444444444444\n" << endl;
  
  // seek to the beginning of the file
  inout.seekg(0);
  // output the all content of the
  // fstream object to stdout
  cout << inout.rdbuf();
  cout << endl;
  return 0;
}

Thanks to help me.
Eric Yang




W Komornicki's Home Page | Main Index | Thread Index