1

How can I convert a GUI C++ application to a console application?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
supriya
  • 11
  • 3
  • 9
    your question is very vague, **please explain your question better**? If you have a C++ gui app with windows and toolbars, you can't convert it into console, unless of course you have a separated shell code then maybe you can re-write the shell. – gideon Mar 02 '11 at 05:38

2 Answers2

8

A good way to start is to separate the "business logic" from the "display logic". That way you can keep the business logic the same, but rewrite the parts that display it on the screen to write to standard output instead. However, if your application already has them mixed together, it's not always easy to separate them out; ideally you want to start with the logic decoupled.

Other than that, you'll want to use std::cout to write to the console, and compile the application as a console application instead of a GUI one.

Colen
  • 13,428
  • 21
  • 78
  • 107
  • You can also use ncurses to hack together an ascii-art gui. Very rudimentary and not recommended for significant projects, but it can work for simple things. – Tim Mar 02 '11 at 06:08
  • If you use curses, don't forget the CDK which makes some curses jobs easier ;) – 0xC0000022L Mar 02 '11 at 06:09
5

If you're asking how to convert your existing VS project from GUI to console, look at project properties under Linker/System, and set the SubSystem to Console.

Erik
  • 88,732
  • 13
  • 198
  • 189