473,699 Members | 2,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I/O std::basic_stre ambuf 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.da t", 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_stre ambuf 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 3169
On Sun, 03 Jul 2005 08:35:11 +0400, Steven T. Hatton
<ch********@ger mania.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_stre ambuf 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_stre ambuf 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_stre ambuf 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
2071
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 subject: http://lists.free.net.ph/pipermail/compsci/2003-October/001510.html > - OpenGL for accelerated graphics.
3
3447
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> template< class MyElem > class MyStreamBuffer : public std::basic_streambuf< MyElem > { protected:
13
4623
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 which also implements ==, <, <=, >, >=, etc. (Those operators are tested and working correctly.) If I assign map = "world", it saves the MyString's correctly in the map. But a subsequent call to map.find("hello") returns map.end(). Even more...
17
3348
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 this uovec at the moment (for Unit-Offset VECtor). I want the class to respond correctly to all usage of STL containers and algorithms so that it is a transparent replacement for std:vector. The options seems to be:
103
48649
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 says about it. What the heck does the binary flag mean? -- 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...
1
2522
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 somehow my OutBuf::xsputn() is not beeing used. But the orginal basic_streambuf::xsputn() calls my OutBuf::overflow(). http://pastebin.com/483016 - OutBuf.h
6
10032
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 hoped I could solve, and I couldn't. Some code he's using, written in 1999, that compiled fine in 1999, no longer does in 2006 with g++ 4. This little bit of code: SimS::SimS (ostream &s) {
2
1757
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, overflow, and underflow. When I see MS VC++6.0 STL code's basic_filebuf implementation, I observed that it is not maintaining any buffering mechanism, instead it is directly handling with the files. Please correct me if I am understanding in a wrong way.
25
8355
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
8687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8615
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9034
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6534
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4376
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.