From: Nebuchadnezzar Newsgroups: comp.os.msdos.djgpp Subject: Re: Strange output formatting! Date: Mon, 3 May 1999 22:24:07 +0100 Message-ID: References: <372D85F3 DOT FDDE9D49 AT yahoo DOT com> NNTP-Posting-Host: quayles1.demon.co.uk X-NNTP-Posting-Host: quayles1.demon.co.uk:193.237.131.218 X-Trace: news.demon.co.uk 925805267 nnrp-07:15173 NO-IDENT quayles1.demon.co.uk:193.237.131.218 X-Complaints-To: abuse AT demon DOT net MIME-Version: 1.0 X-Newsreader: Turnpike (32) Trial Version 3.05 Lines: 41 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com In article <372D85F3 DOT FDDE9D49 AT yahoo DOT com>, Chong Kai Xiong 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