473,657 Members | 2,348 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
1 3217

"Tony Boloney" <tb******@lycos .com> wrote in message
news:cm******** *@snic.vub.ac.b e...
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4019
by: Eitan | last post by:
Hello, I am using Visual Studio.net 2003. I am trying to find how to create Win32 DLL & Win32 Static Library. When going through the wizard it does not show me the option for these two project types. Any Idea? Eitan
19
3836
by: ernst.stiegler | last post by:
Hello, I just want to read a whole line from a console input. What I don't understand is that I always have to press ENTER twice in order to see the line I've entered. Here's my code : #include <string> #include <iostream>
1
4527
by: Bill Sun | last post by:
Hi, I just want to using a console application in the .net enviroment. Before the main(), I using the #include "iostream.h" but the .net tell me: c:\project\console\console\console.cpp(11): fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory
7
2227
by: Brian | last post by:
Hi, I have been trying to tune my vc7 compiled applications to perform at the same or (preferably) better speed of the same vc6 application. Both versions of my code are compiled with optimization, but the vc7 is quite slow in comparison to the vc6 one. My timing test was rougly 71 seconds for vc6 and 103 seconds for vc7. The total number of calculations was roughly 191 million for vc6 and 89 million for vc7 after 13 seconds of run...
5
2387
by: David | last post by:
Hello, I really need help. I use C++ VisualStudio.net version 2002. I tried to create a very simple console app. However, it won't compile, then I found out that I am missing two important files that pre-load when you create a Console Application, AssemblyInfo.cpp and Resource.h files. According to the long search I did, these files help compile statements like Console::WriteLine() or int _tmain(). I tried repariing it but it still...
7
4197
by: Robert | last post by:
Hello, I'm using Pythonwin and py2.3 (py2.4). I did not come clear with this: I want to use win32-fuctions like win32ui.MessageBox, listctrl.InsertItem ..... to get unicode strings on the screen - best results according to the platform/language settings (mainly XP Home, W2K, ...). Also unicode strings should be displayed as nice as possible at the console with normal print-s to stdout (on varying platforms, different
1
7912
by: AlwaysPerplexed | last post by:
Hi, I'm somewhat stuck and could really appreciate some help. I'm writing a little program using the OpenCV libraries, I started this as a Win32 Console Application and everything worked fine. I now need a GUI, so i started a Windows Forms Application, however when i included the OpenCV header files (before adding any source) i got a bunch of errors (see the bottom of my post). I have been informed that this is because I'm using .NET...
0
2438
by: jbenezech | last post by:
Hi all , I have a perl/java app running under Win32. The application consists of a perl service (Win32::Daemon) and of java classes. The perl service calls every xx hours java classes to perform some action. The java call looks like this: Win32::SetChildShowWindow(0); Win32::Process::Create(
11
41267
by: gumboots | last post by:
Hi there guys, I've recently purchased "Sam's Teach Yourself C++ Fifth Edition" (About a week before the 6th edition came out) I'm trying to work through the book, but in trying to compile Hello World, I keep getting an error instead of it making the program. I've looked around the internet for a reason, but come up stuck. My only assumption would be that the fifth edition is upgraded to suit newer compilers? (I downloaded Visual C++...
0
8399
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8827
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8504
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7337
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2732
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1622
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.