Mail Archives: djgpp/1999/05/04/07:23:59
In article <372D85F3 DOT FDDE9D49 AT yahoo DOT com>, Chong Kai Xiong
<w_velocity AT yahoo DOT com> writes
>Actually, there's nothing wrong with the output, at least it did what you
>specified. What you got has to do with the way output streams (ostreams)
>work...when you write
>
> cout << "Some box data is " << get_volume(x, y, z) << "\n";
>
>it actually translates to:
>
> int Temp = get_volume(x, y, z);
> cout << "Some box data is ";
> cout << Temp << "\n";
>
>Can't really phrase the explanation but here goes my bad English =) :
>what really happens is that the string "Some box data" is first fed into
>a output stream. Next the program calls get_volume() to obtain the result
>value to output which is then appended onto the stream. Next, "\n" is
>added. The data stream is then directed to 'cout' which starts printing
>it character by character to screen from the current cursor position.
>printf() outputs directly to screen and does not affect the stream, which
>is why you didn't get the dimensions printed in the correct position.
>The function was called first before the stream was outputted to screen,
>so the dimensions appeared in front instead. See my point? I hope my
>lengthy explanation helped... =)
>
>Have a nice day...
>
>Descender
>
Cheers, that made it quite a bit clearer.
I think that the general rule is just not to mix the C and C++ output
things!
-----BEGIN GEEK CODE BLOCK-----
GCS d- s+:++ a--- C+++> UL++> P+> L++> E? W+ N+++ o+ K? w--
!O M-- V? PS++ PE Y-- PGP--- t+ 5@ X- R+ tv++ b+> DI? D++>
G> e-> h! r y--
------END GEEK CODE BLOCK------
Nebuchadnezzar
- Raw text -