C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Why seekp and seekg move both pointers?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Hector C++
Guest





PostPosted: Thu Feb 23, 2006 6:19 pm    Post subject: Why seekp and seekg move both pointers? Reply with quote



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





PostPosted: Fri Feb 24, 2006 5:06 pm    Post subject: Re: Why seekp and seekg move both pointers? Reply with quote



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





PostPosted: Sun Feb 26, 2006 6:20 am    Post subject: Re: Why seekp and seekg move both pointers? Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.