want info. abut flush

i dont understand what the function "flush" does
please answer
and one more,
is there a way that we output a set of data
only after a certain while in program execution
without storing it in a file and again
printing it after reading from that file
eg....
i declared a variable 'va'
in c++ code ..the value of va changes based upon
the input given by user which is done many times in program
and i like to print the value of va many times in program
but,only after the user is satisfies with his number of inputs
so i need to output all the values va all at a time at the only at the end

>but using cout or any object of ofstream also makes the data to be outputted
You're mixing things up. Any object derived from ostream contains a buffer. It's this buffer that "makes the data to be outputted", and when it sends characters from the buffer to the destination (the destination could be a file, your monitor, or something else), we call this a flush. Now, the buffer flushes itself periodically without intervention from you (such as when it fills up or you request input from a tied stream). However, if you want the buffer to flush itself outside of those times, the flush member function is there so that you can force a flush.

So the difference is that flush gives you more control over when the buffer is flushed, rather than waiting until the implementation is ready.

i think i got it,
now ,is there a way that we stop flushing action of
output stream buffer for a while either by
........increasing the capacity that the buffer can hold
or
.........by "removing any ties" that the ostream object has
with istream objects

now,
if i have a code whose only
only work is to print "hello world"
to the monitor
and in that code i increased the capacity
of the buffer so that it is not saturated
by the length of statement "hello world"
and i even do not remove ties
of that ostream (cout in this case)object with
istream objects(cin in this case)
then is it not possible to display output
without using 'flush '
__________________________________________________________
And to what extent can i increase the capacity of buffer?
____________________________________________________________

>then is it not possible to display output without using 'flush'
What in the world are you talking about? The only way to send output to the destination is to flush the buffer, and the buffer gets flushed automatically according to certain rules. You only need to call the flush member function when the automatic flushing isn't good enough.

>And to what extent can i increase the capacity of buffer?
You can replace the buffer with your own, thus the extent is limitless.

narue,
you told me of two cases when buffer gets flushed (when buffer gets filled up or while input is from a tied stream )
tell me the other cases
if these are the only cases
and if input is not from tied stream
then buffer should not get flushed until "saturated "
and what if i increase the capacity of buffer !!!?

> i declared a variable 'va'
> in c++ code ..the value of va changes based upon
> the input given by user which is done many times in program
> and i like to print the value of va many times in program
> but,only after the user is satisfies with his number of inputs
> so i need to output all the values va all at a time at the only at the end

this was your original problem. and dragon gave you a couple of reasonable solutions. all your questions about flush and stream buffers have been taking you farther away from a solution to the actual problem that you are facing.a. narue informed you that flushing of the stream does happen automatically even if you do not call flush.b. setting the buffer size to a large value by something like char buf[1024*128] ; cout.rdbuf()->pubsetbuf(buf,sizeof(buf)); does not guarantee that the stream will not get flushed. the c++ standard only defines the behavior of pubsetbuf(0,0); this has the effect of turning off any buffering. pubsetbuf() called with any other values may or may not change the flushing behavior of the stream.
usually, calls to pubsetbuf() with non-zero values modify the flushing behaviour for filebufs (used with file streams). the specific behavior has to be defined in the documentation of the implementation (it is "implementation defined"). and you could look this up in the documentation provided by the specific implementation you are using.c. the only portable way by which you can guarantee the behaviour you are looking for is by creating your own stream buffer class. this is not a difficult task; you can inherit all the functonality from a std::streambuf and modify only the flushing behaviour.

however, there are much easier ways to solve the problem; eg. buffer all your output to a stringstream till you are ready to display it to the user. at that point, dump the contents of the stringstream on standard output.

I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...