What's new

outputting in a command prompt from a windows app

mesman00

What's that...?
this is what i want to do. i am writing a windows app (using MFC) and want to output messages to the command prompt using the iostream lib (cout). how do i go about doing this. since i have been using java for hte last six months i know in java you can just run the executable from the command prompt and the windows app will open, yet write messages to the command prompt when needed, but i tried this in c++ and it does not work. thus, how do i go about doing this. thanks.
 

smcd

Active member
You can make a "console app" in VC++ and then use windows functions to make a window appear, and still have the console window in the background? That's what I've done in the past, it works OK, though I used WinAPI instead of MFC.

Another possibility is to have 2 separate applications, and the MFC execute the other, redirecting the STDIN of the spawned process to a pipe & the spawned console application just output everything it receives in STDIN to STDOUT.
 

refraction

PCSX2 Coder
the way id say is what sethmcdoogle said. if you goto Project/Properties then click Linker followed by System, the top option should be SubSystem, if you set this to console it should make a command prompt window load with your program, then you can use cout commands to output to it :)
 
OP
mesman00

mesman00

What's that...?
refraction said:
the way id say is what sethmcdoogle said. if you goto Project/Properties then click Linker followed by System, the top option should be SubSystem, if you set this to console it should make a command prompt window load with your program, then you can use cout commands to output to it :)

where is this setting. if i go to project project file menu there is no properties option, only settings. so if i open setting and go to link there is no system option. if i right click on the project and click properties there is no linker option. are you using msvc++ 6.0?
 

refraction

PCSX2 Coder
it shouldbe there, on you have to have the project name selected in the solution browser thing, say your project is called flob, youll see it like this

flob
sourcefiles
-main.cpp
-something.cpp
headers
-main.h
-something.h


make sure you select the project name at the top (flob in the example) before you goto the project menu.
 

smcd

Active member
Assuming VC++6 ... Alt+F7 opens project options (don't have a file selected, choose the project itself up top in the file list) and go to the Link tab. In the "Project Options:" edit box you'll see somewhere in there "/subsystem:XXXXXXX" where XXXX is gonna be either "console" or "windows" (can be other things too i imagine though not likely)
 
OP
mesman00

mesman00

What's that...?
yah, ok, i had already tried that. since it's an MFC app there is no main function, but the console app looks for one. thus generating the following error:

Code:
libcmtd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
 

smcd

Active member
Yeah, I did say I've never tried that with MFC. You could go the alternate route mentioned above, and have a child program that just redirects any STDIN it gets to STDOUT? (this will work in practically ANY OS, and should do well in MFC)
 

Top