Thread: Output

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    22

    Question Output

    Hi Programmers!
    I need Help.
    When I type this simple Program:-
    Code:
    #include<iostream.h>
    int main()
    {
        cout<<"Alok";
        return 0;
    }
    I get the out put but I get it in DOS. How do I make it appear in a white screen and the output just opens and close immediately by which I dont even get time to read! Please tell me how do i configure it!

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Standard C++ has no graphical user interface buit-in. If you want anything more than a console window interface, you have to use a graphics library which is a lot more complicated and advanced than the code you have now.

    To stop the console (not DOS) window from disappearing, you can just open up your own console and run the program from there. You can also add code to your program to wait for the user to hit enter (in this case add cin.get(); before the return 0; ). There are FAQs about this issue as it is very common.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    BTW:
    Code:
    #include <iostream>
    
    int main()
    {
      std::cout << "Alok";
      return 0;
    }
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    22

    Yes..

    Yes. I understood the cin.get(); but can you tell me to do this without opening the console?
    Thank you!

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    See this FAQ and this FAQ.

    The idea is to put-in an extra cin.get(); at the end of your program so that the program sits there and waits for a keypress before the window closes.

    The console window will open automatically when you click your EXE file.

    The console Window will close automatically when your program is done.

    This problem has nothing to do with C++, it's a "feature" of Windows.
    Last edited by DougDbug; 09-29-2006 at 10:55 AM.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> I understood the cin.get(); but can you tell me to do this without opening the console?
    The cin.get() solution was to be used instead of opening your own console window.

    Unless you mean the part about having a white screen, in which case you'll have to do some research about GUI programming.

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    22
    In my school (Borland C++), When I do a program...It comes in white screen (not in DOS) and doesn't disappear immediately and I don't even have to use the return 0; statement! How Come?

  8. #8
    Registered User
    Join Date
    Aug 2006
    Posts
    163
    Quote Originally Posted by alokrsx
    In my school (Borland C++), When I do a program...It comes in white screen (not in DOS) and doesn't disappear immediately and I don't even have to use the return 0; statement! How Come?
    That would be something the borland compiler is adding in for you. It's a lot of code to get that white screen, and so you shouldn't be worried about it right now. Just deal with the console window for a year or so, you'll survive.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. code output...
    By roaan in forum C Programming
    Replies: 6
    Last Post: 07-03-2009, 02:22 AM
  2. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  3. Replies: 4
    Last Post: 11-30-2005, 04:44 PM
  4. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM