By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,795 Members | 1,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,795 IT Pros & Developers. It's quick & easy.

iostream & Adding Console I/O to a Win32 GUI App

P: n/a
Hi all,
I'm trying to use the method described in the article

Adding Console I/O to a Win32 GUI App
http://dslweb.nwnexus.com/~ast/dload/guicon.htm

to output info to a separate console window.

I copy-pasted the code into my project and uncommented the last line

ios::sync_with_stdio();

to point cout, cin, etc to the console as well, but for some reason this
doesn't work. Using

fprintf(stdout, "some text")

works, but

cout << "some text" << endl

does nothing.
Could this have something to do with my configuration? (VS.NET, STLport
4.6 with own iostreams (no wrapper), DirectX9)?
Thanks!

T

Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Tony Boloney" <tb******@lycos.com> wrote in message
news:cm*********@snic.vub.ac.be...
Hi all,
I'm trying to use the method described in the article

Adding Console I/O to a Win32 GUI App
http://dslweb.nwnexus.com/~ast/dload/guicon.htm

to output info to a separate console window.

I copy-pasted the code into my project and uncommented the last line

ios::sync_with_stdio();

to point cout, cin, etc to the console as well, but for some reason this
doesn't work. Using

fprintf(stdout, "some text")

works, but

cout << "some text" << endl

does nothing.
Could this have something to do with my configuration? (VS.NET, STLport
4.6 with own iostreams (no wrapper), DirectX9)?


The author of that article seems to misunderstand what sync_with_stdio does.
Its purpose is to synchronize output to stdout with cout (for instance) so
that writes to these two stream appear in the right order. It certainly has
nothing to do with redirecting anything. In any case synchronization is on
by default and you would normally call sync_with_stdio to turn it off.

stdout and cout are guaranteed to write to the same place by the C++
standard, but the author of that article has written a lot of non-standard
code which has presumably broken that guarantee. He seems to be redirecting
stdout and then assuming that will simply redirect cout.

It could be that if you switch to another STL (for instance the one that
ships with the MS compiler) that this code will work, but I think the only
way to find out is to try it.

Alternatively you could do the proper thing which is to write you own custom
stream buffer classes which will do console I/O for you. Or find something
like that on the web, I'm sure it's been done many times before.

John
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.