 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Hector C++ Guest
|
Posted: Thu Feb 23, 2006 6:19 pm Post subject: Why seekp and seekg move both pointers? |
|
|
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 ] |
|
| Back to top |
|
 |
Dietmar Kuehl Guest
|
Posted: Fri Feb 24, 2006 5:06 pm Post subject: Re: Why seekp and seekg move both pointers? |
|
|
Hector C++ wrote:
| Quote: | 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 (AT) yahoo (DOT) 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 ] |
|
| Back to top |
|
 |
Hector C++ Guest
|
Posted: Sun Feb 26, 2006 6:20 am Post subject: Re: Why seekp and seekg move both pointers? |
|
|
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 ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|