Results 1 to 7 of 7

Thread: keeping the console window open to see your program

  1. #1
    UKMuFFiN
    Guest

    keeping the console window open to see your program

    Sorry for the title, was hard to explain my question in a title. Its prob not even the right forum to put it in :S

    Im learnign c++, and when you start you make simple programs that run in a console window, but when you run the program if its something simple like for example, the "Hello World!" you don't see it because obviously the computer does it so fast when it gets to the program it closes. You can obviously put another std::cin at the end so the program needs something entered before it ends but none of the tutorials have this and they never say anything about the console closing. So is there a setting or somthing for command promt i can change for it to stay open after a program is run?

    Cheers.

  2. #2
    The King of Vague Steve B's Avatar
    Join Date
    Oct 2005
    Location
    Glasgow
    Posts
    5,051
    Thanks
    116
    Thanked
    67 times in 63 posts
    put getch() at the end just before return 0; that should do it

  3. #3
    UKMuFFiN
    Guest
    Cheers Lol, i just noticed this is in the connectivity - broadband & networking forum :S.

    I thought i put it in the binarys one. Ooops.

  4. #4
    Senior Member skuzgib's Avatar
    Join Date
    Oct 2004
    Location
    Bromsgrove, Worcestershire / Durham
    Posts
    1,917
    Thanks
    6
    Thanked
    1 time in 1 post
    You could also add

    system("PAUSE");

  5. #5
    Gentoo Ricer
    Join Date
    Jan 2005
    Location
    Galway
    Posts
    11,039
    Thanks
    1,014
    Thanked
    944 times in 704 posts
    • aidanjt's system
      • Motherboard:
      • Asus Strix Z370-G
      • CPU:
      • Intel i7-8700K
      • Memory:
      • 2x8GB Corsiar LPX 3000C15
      • Storage:
      • 500GB Samsung 960 EVO
      • Graphics card(s):
      • EVGA GTX 970 SC ACX 2.0
      • PSU:
      • EVGA G3 750W
      • Case:
      • Fractal Design Define C Mini
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • Asus MG279Q
      • Internet:
      • 240mbps Virgin Cable
    Code:
    char quit;
    while (quit != 'q') {
        quit << cin;
    }
    return 0;
    that's why i usually do, or something to that effect to control returning main, i prefer that as it's proper standard, and adjustable to suit interactive programs.
    Quote Originally Posted by Agent View Post
    ...every time Creative bring out a new card range their advertising makes it sound like they have discovered a way to insert a thousand Chuck Norris super dwarfs in your ears...

  6. #6
    UKMuFFiN
    Guest
    So why don't books/tutorials, esp ones that know your running your first progs in cmd tell you that it will close before you even see it run?

    std::cout << "ta for all the help.";

  7. #7
    Gentoo Ricer
    Join Date
    Jan 2005
    Location
    Galway
    Posts
    11,039
    Thanks
    1,014
    Thanked
    944 times in 704 posts
    • aidanjt's system
      • Motherboard:
      • Asus Strix Z370-G
      • CPU:
      • Intel i7-8700K
      • Memory:
      • 2x8GB Corsiar LPX 3000C15
      • Storage:
      • 500GB Samsung 960 EVO
      • Graphics card(s):
      • EVGA GTX 970 SC ACX 2.0
      • PSU:
      • EVGA G3 750W
      • Case:
      • Fractal Design Define C Mini
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • Asus MG279Q
      • Internet:
      • 240mbps Virgin Cable
    Technically it doesn't, ANSI/ISO C++ expects you to have a terminal open already, i.e. start->run, type "cmd" enter, and run it there. Windows (and other DEs) close the terminal windows after main() returns, if it opened the terminal, whether the return value be a zero or non-zero value. So it's pretty much a Windows cravet with commandline software.

    And most welcome
    Last edited by aidanjt; 29-06-2006 at 12:40 AM.
    Quote Originally Posted by Agent View Post
    ...every time Creative bring out a new card range their advertising makes it sound like they have discovered a way to insert a thousand Chuck Norris super dwarfs in your ears...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How do I restore "Show Desktop" icon in the Quick Launch bar of Windows?
    By davidstone28 in forum Help! Quick Relief From Tech Headaches
    Replies: 7
    Last Post: 09-01-2006, 01:02 PM
  2. Window Tints - New Legislation Planned
    By Barakka in forum Automotive
    Replies: 14
    Last Post: 05-05-2005, 03:32 PM
  3. Recovery console "access denied" Help
    By iranu in forum Software
    Replies: 0
    Last Post: 20-01-2005, 12:25 PM
  4. Open Source Articles
    By r1zeek in forum General Discussion
    Replies: 6
    Last Post: 13-08-2004, 09:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •