Topic: Why seekp and seekg move both pointers?
Author: "Hector C++" <hhcalderon@yahoo.com>
Date: Thu, 23 Feb 2006 12:19:38 CST Raw View
I thought that the 'put' and 'get' pointers were different, but the
following program shows they are not. Is this standard?
#include <fstream>
#include <iostream>
using namespace std;
int main( int argc, const char * argv[] )
{
const char * fn = "test.txt";
fstream f1(fn, fstream::binary|fstream::in);
fstream f2(fn, fstream::binary|fstream::out);
if (!f1.is_open() || !f2.is_open())
{
cout << "Couldn't open\n";
system("pause");
return 1;
}
cout << "f1.tellg: " << f1.tellg() << "\nf2.tellg: " << f2.tellg()
<< "\n\tf1.tellp: " << f1.tellp() << "\n\tf2.tellp: " << f2.tellp()
<< endl;
f1.seekg(10);
f2.seekg(15);
cout << "f1.tellg: " << f1.tellg() << "\nf2.tellg: " << f2.tellg()
<< "\n\tf1.tellp: " << f1.tellp() << "\n\tf2.tellp: " << f2.tellp()
<< endl;
f1.seekp(20);
f2.seekp(25);
cout << "f1.tellg: " << f1.tellg() << "\nf2.tellg: " << f2.tellg()
<< "\n\tf1.tellp: " << f1.tellp() << "\n\tf2.tellp: " << f2.tellp()
<< endl;
system("pause");
return 0;
}
//Output
//f1.tellg: 0
//f2.tellg: 0
// f1.tellp: 0
// f2.tellp: 0
//f1.tellg: 10
//f2.tellg: 15
// f1.tellp: 10
// f2.tellp: 15
//f1.tellg: 20
//f2.tellg: 25
// f1.tellp: 20
// f2.tellp: 25
//Press any key to continue . . .
Hector C++
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: dietmar_kuehl@yahoo.com (Dietmar Kuehl)
Date: Fri, 24 Feb 2006 16:39:16 GMT Raw View
Hector C++ wrote:
> I thought that the 'put' and 'get' pointers were different, but the
> following program shows they are not. Is this standard?
In the class template 'basic_streambuf' the put and get positions are
indeed independent and you can have stream buffers maintaining different
put and get positions. However, for files you have only one joint
position. This is specified in 27.8.1.1 (lib.filebuf) paragraph 3.
--
<mailto:dietmar_kuehl@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: "Hector C++" <hhcalderon@yahoo.com>
Date: Sun, 26 Feb 2006 00:20:03 CST Raw View
So it is standard ... thanks for your answer.
I'll get me one of those 'standard' books. Should I get one now or is
any 'update' coming in the following months?
Hector C++
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]