Thread: Console vs. Command windows

  1. #1
    Registered User
    Join Date
    May 2013
    Posts
    6

    Console vs. Command windows

    Hi,

    I have written a code modeled after one in a textbook, but it will only run as an .exe in a command prompt window. I want it to operate directly out of the visual studio 2012 debugger console as a .cpp. The headers look the same to me, so I can't figure out what I need to change to make it open the way I desire. Is there a stock header for each, and I just can't tell them apart? Please help.

  2. #2
    Registered User
    Join Date
    May 2012
    Posts
    505
    Quote Originally Posted by GigTu View Post
    Hi,

    I have written a code modeled after one in a textbook, but it will only run as an .exe in a command prompt window. I want it to operate directly out of the visual studio 2012 debugger console as a .cpp. The headers look the same to me, so I can't figure out what I need to change to make it open the way I desire. Is there a stock header for each, and I just can't tell them apart? Please help.
    C and C++, and other languages, have a concept of "standard input" and "standard output". In C standard output is A FILE * called stdout, and is used implictly in functions like printf(). In C++ it's a stream object called cout. But the same underlying operating system functions will be called.
    The system ties standard input and standard output to some physical reality, which might be dots in a console window, electric pulses going down a telephone wire, a printer, or some internal process in Visual Studio 2012.

    Windows also has the windowing GUI. To use these functions, you need to include windows.h, or some high level file which includes windows.h internally. The windowing GUI doesn't have the same sort of flexibility as standard output, it will always be physically realised as pixels on a screen.

    Visual Studio like you to tell it whether you are writing a GUI program or a standard input/output, or "console" program. It also have various flavours - it likes to persuade you to include a funny header called stdafx.h and use unicode rather than Ascii. Normally you won't want to do this - you just want portable standard C or C++.

    Another quirk of Visual Studio is that when you run programs under the debugger, they tend to open a console window, then close it as soon as the program terminates. often this happens more quickly than you can read the output. There are ways of stopping it from doing this, but basically it's just a silly design feature. If you run the program from a DOS box, it will work as expected.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    https://github.com/MalcolmMcLean


  3. #3
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    You can set a break point on the final return from main() so that you can at least see the dos console window before it's closed. This works with release builds also.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Controlling console command window input
    By DanFraser in forum C# Programming
    Replies: 0
    Last Post: 11-27-2007, 10:34 AM
  2. How to execute a console command from your app?
    By GUIPenguin in forum C# Programming
    Replies: 2
    Last Post: 07-06-2006, 09:36 AM
  3. Replies: 5
    Last Post: 04-10-2006, 03:03 PM
  4. in program command console
    By howzer in forum C++ Programming
    Replies: 11
    Last Post: 03-19-2006, 03:12 PM
  5. cd command in linux console
    By TheUnheardHuman in forum Tech Board
    Replies: 2
    Last Post: 11-19-2002, 03:59 PM