Sign in to follow this  

strange output in VC6.0

This topic is 4303 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

It is because both C and C++ I/O functions uses buffering. And they don't share the buffers.

You can flush the output for one of them then uses the other or in MSVC, you can set the system libraries to sync. (flush) the I/O buffers every time.

Sorry that I forget about the functions and don't have the MSDN on hand. You can look the functions up there.

Share this post


Link to post
Share on other sites
The order of appearence of text, when you use both C and C++ output functions without synchronization, is undefined and dependent on implementation and buffering details. This means that you can get different results on different compilers.

By default, cout<<"Text"; does not mean "display the text" but rather, "display the text when you feel like it". This allows displaying the text two hours after that, even if in the mean time other strings have been displayed through printf.

Also, it's iostream and cstdio.

Share this post


Link to post
Share on other sites
Quote:
Original post by ToohrVyk
The order of appearence of text, when you use both C and C++ output functions without synchronization, is undefined and dependent on implementation and buffering details. This means that you can get different results on different compilers.


Implementation-defined in the sense that if you're implementing a standard-compliant library, the order is defined, otherwise it's not defined.

If you're using <iostream> (the C++ standard library console iostreams) and std::sync_with_stdio(false) has not been called before the first use of std::cout, std::cerr, or std::clog, then those output streams shall be synchronized with stdout (or stderr as appropriate). It is required by the standard and well-defined behaviour. You can rely on them outputting in the order you write to them.

Of course if you're using <iostream.h>, anything could happen, including reformatting your hard drive, since that header is not a part of any published standard.

Also, MSVC++6 was in no way a standards-compliant compiler, let alone C++ library, so all bets on its behaviour are off to start with.

Share this post


Link to post
Share on other sites

This topic is 4303 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this