473,402 Members | 2,050 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.

ostream_iterator

Hi,
please consider the following prog (SunOS 5.8,g++ compiler)
when I ran it through the debugger , I found that the program doesn't
output till either the "\n" or the exit .
(debugger ..Single stepping until exit from function _start ...)
what does reaching exit or \n have to do with cout or ostream_iterator
?
#include <iostream>
#include <string>
#include <iterator>
using namespace std ;

int main()
{
ostream_iterator<string> out(cout , " ") ;
*out ="hello" ;
out++ ;
*out = "world" ;
out++ ;
*out = "\n" ;
out++ ;
*out = "again" ;

}

regards,
--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
Jul 19 '05 #1
4 3181

"Aman" <am**@techie.com> wrote in message
news:3c************************************@mygate .mailgate.org...
Hi,
please consider the following prog (SunOS 5.8,g++ compiler)
when I ran it through the debugger , I found that the program doesn't
output till either the "\n" or the exit .
(debugger ..Single stepping until exit from function _start ...)
what does reaching exit or \n have to do with cout or ostream_iterator
?
#include <iostream>
#include <string>
#include <iterator>
using namespace std ;

int main()
{
ostream_iterator<string> out(cout , " ") ;
*out ="hello" ;
out++ ;
*out = "world" ;
out++ ;
*out = "\n" ;
out++ ;
*out = "again" ;

}


Output is not guaranteed to be delivered to the
device attached to a stream until a newline is
inserted into the stream, or the stream is explicitly
flushed, or the stream object is destroyed, or if
it is a file stream, the file is closed.

This is by design.

A 'special case' exists with regard to 'cin' and 'cout':
An insertion to 'cout' will first cause an automatic 'flush'
of 'cin' if any data remain in its stream buffer (see 'tie()')

HTH,
-Mike

Jul 19 '05 #2
Thanks , makes sense.
Is there anyplace where this behaviour is documented ?
url / book reference would be good.

regards,
Aman

--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
Jul 19 '05 #3

"Aman" <am**@techie.com> wrote in message
news:f8************************************@mygate .mailgate.org...
Thanks , makes sense.
Is there anyplace where this behaviour is documented ?
http://tinyurl.com/31yw
url / book reference would be good.


http://www.langer.camelot.de/iostreams.htm
http://www.josuttis.com/libbook/

-Mike
Jul 19 '05 #4
Thanks a lot !!.

regards,
Aman.
--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
Jul 19 '05 #5

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

Similar topics

2
by: Chris Mantoulidis | last post by:
Hello all... I get an error message for the following program by the compiler: #include <iostream> #include <string> using namespace std; ostream_iterator<string> oo(cout);
12
by: Fraser Ross | last post by:
a std::ostream_iterator can be constructed from a ostream but not a fstream. If the fstream is opened with the out mode how can I get a ostream_iterator? I am not using a pointer to any base class....
8
by: Jeff | last post by:
std::copy to std::ostream_iterator doesn't seem to work with maps and pairs. Shouldn't I expect something like this to work? The G++ error message when USE_COPY_TO_PRINT is defined as a...
5
by: Wiseguy | last post by:
consider the following: ostream_iterator<int> i(cout,""); cout << setw(3); copy(int_list.begin(),int_list.end(),i); the problem is that the field width restriction is only active for the...
4
by: Nan Li | last post by:
Hello, Can any one get the 'copy' statement below to work? I want it to do the same thing as the 'for' loop does. But I got a lot of STL error during compile. Thanks, Nan #include <map>
2
by: alzforu | last post by:
The code in which i m facing the problem is: //file stream.cc #include <vector> #include <algorithm> #include <iostream> using namespace std;
3
by: Evyn | last post by:
Hi, Can someone tell me why I always get an error like "`ostream_iterator' undeclared (first use this function) " when using ostream_iterator. I have for example tried the following code taken...
5
by: krzysztof.konopko | last post by:
I cannot compile the code which defines a std::map type consisting of built in types and operator<< overload for std::map::value_type. See the code below - I attach a full example. Note: if I...
2
by: subramanian100in | last post by:
Consider the following piece of code: #include <iostream> #include <fstream> #include <vector> #include <string> #include <utility> #include <iterator> #include <algorithm> int main()
0
by: ShaunJ | last post by:
I'm trying to use an ostream_iterator to iterate over a set of pairs. I've used an ostream_iterator over other types and had no problem. However, with the following code snippet, I'm getting a...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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,...
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.