473,402 Members | 2,072 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

I/O std::basic_streambuf put and get areas?

I'm a bit confused about a statement in TC++ST §13.10. It's in reference to
this example:

/* The following code example is taken from the book
* "The C++ Standard Library - A Tutorial and Reference"
* by Nicolai M. Josuttis, Addison-Wesley, 1999
*
* (C) Copyright Nicolai M. Josuttis 1999.
* Permission to copy, use, modify, sell and distribute this software
* is granted provided this copyright notice appears in all copies.
* This software is provided "as is" without express or implied
* warranty, and with no claim as to its suitability for any purpose.
*/
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
// open file ``example.dat'' for reading and writing
filebuf buffer;
ostream output(&buffer);
istream input(&buffer);
buffer.open ("example.dat", ios::in | ios::out | ios::trunc);

for (int i=1; i<=4; i++) {
// write one line
output << i << ". line" << endl;

// print all file contents
input.seekg(0); // seek to the beginning
char c;
while (input.get(c)) {
cout.put(c);
}
cout << endl;
input.clear(); // clear eofbit and failbit
}
}

He says "Although two different stream objects are used for reading and
writing, the read and write positions are tightly coupled. seekg() and
seekp() call the same member function of the stream buffer.10"

footnote 10 says: "Actually this function can distinguish whether the read
position, the write position, or both positions are to be modified. Only
the standard stream buffers maintain one position for reading and writing."

This is the Doxygen of libstdc++:
http://gcc.gnu.org/onlinedocs/libstd...ce.html#l00967

I'm trying to make heads or tails out of this. If the put pointer and get
pointer are synchronized, then why have two of them? This is what the
std::basic_streambuf pointer declarations look like:

Protected Attributes
locale _M_buf_locale
char_type * _M_in_beg
char_type * _M_in_cur
char_type * _M_in_end
char_type * _M_out_beg
char_type * _M_out_cur
char_type * _M_out_end
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell
Jul 23 '05 #1
3 3157
On Sun, 03 Jul 2005 08:35:11 +0400, Steven T. Hatton
<ch********@germania.sup> wrote:

[]
http://gcc.gnu.org/onlinedocs/libstd...ce.html#l00967
I'm trying to make heads or tails out of this. If the put pointer and
get
pointer are synchronized, then why have two of them?
Because you may want to maintain different file positions for read and
write in your streambuf. Why prohibit it?
This is what the
std::basic_streambuf pointer declarations look like:

Protected Attributes
locale _M_buf_locale
char_type * _M_in_beg
char_type * _M_in_cur
char_type * _M_in_end
char_type * _M_out_beg
char_type * _M_out_cur
char_type * _M_out_end


Please note, these are buffer positions, not file.

--
Maxim Yegorushkin
<fi****************@gmail.com>
Jul 23 '05 #2
Steven T. Hatton wrote:
I'm trying to make heads or tails out of this. If the put pointer
and get pointer are synchronized, then why have two of them? This is
what the std::basic_streambuf pointer declarations look like:


Among other things, you can use a stream buffer with separate get and put areas
to create an iostream representing a TCP connection, with separate input and
output channels.

Jonathan
Jul 23 '05 #3
Jonathan Turkanis wrote:
Steven T. Hatton wrote:
I'm trying to make heads or tails out of this. If the put pointer
and get pointer are synchronized, then why have two of them? This is
what the std::basic_streambuf pointer declarations look like:


Among other things, you can use a stream buffer with separate get and put
areas to create an iostream representing a TCP connection, with separate
input and output channels.

Jonathan

I was tired when I posted that. What I was really trying to get at is
whether that specification has changed since he wrote the book. And also
whether I /could/ create a buffer that had independed put and get areas.
And also how the condition he was describing was produced. None of that
was clear to me from looking at the source, but I had not studied it very
closely. DR60 is kind of long, and I wasn't able to determine exactly what
the note in the implementation was reffering to.
--
If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true.-Bertrand Russell
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jonathan P. | last post by:
....that would be for desktop-based apps, games, 3d graphics, and multimedia. ....thanks to APIs and bindings like Pygame, PyOpenGL, PyGtk and PyGtkGLExt. A summary of a lengthy post on the...
3
by: | last post by:
I can not seem to get this to compile with either gcc 3.4 or MSVC++ .NET 2003... (source follows first): ---= BEGIN MyStreamBuffer.h =--- // #IFDEF redundancy left out. #include <streambuf> ...
13
by: jstanforth | last post by:
This is probably a very obvious question, but I'm not clear on what operators need to be implemented for std::map.find() to work. For example, I have a class MyString that wraps std::string, and...
17
by: Michael Hopkins | last post by:
Hi all I want to create a std::vector that goes from 1 to n instead of 0 to n-1. The only change this will have is in loops and when the vector returns positions of elements etc. I am calling...
103
by: Steven T. Hatton | last post by:
§27.4.2.1.4 Type ios_base::openmode Says this about the std::ios::binary openmode flag: *binary*: perform input and output in binary mode (as opposed to text mode) And that is basically _all_ it...
1
by: Johannes Barop | last post by:
Hello, i try to implement a streambuffer. I overwrote streambuf::overflow() and streambuf::xsputn(). Both are protected and virtual (http://www.cplusplus.com/ref/iostream/streambuf/). But...
6
by: Geoffrey S. Knauth | last post by:
It's been a while since I programmed in C++, and the language sure has changed. Usually I can figure out why something no longer compiles, but this time I'm stumped. A friend has a problem he...
2
by: sri | last post by:
Dear All, I would like to implement file buffer class to make avialable buffering mechanism to ifstream or own customized file stream. My question is what are the semantics for seekoff,...
25
by: Bala2508 | last post by:
Hi, I have a C++ application that extensively uses std::string and std::ostringstream in somewhat similar manner as below std::string msgHeader; msgHeader = "<"; msgHeader += a; msgHeader...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.