Thread: Cant compile and run

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    2

    Cant compile and run

    Im just learning c++ so ignore my ignorance but when i build up a program and compile it, its ok, but when i try to run it, a black box pops up and goes within a split second. This happens with many dos programs i have run. any ideas?

    thx

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Yeah - check out the FAQ.

    What's happening is the computer does everything you ask it to do, and when it's done, it closes the window your program was running in. The way to solve this is to have the computer wait for input at the end of your program. Look for FAQ entries about having your program wait for input.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    2
    Thx for the help, i googled "wait for input C++"

    And it told me to enter system("PAUSE"); at the end, worked a treat, thx

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Okay, now check the FAQ and know that doing so is not recommended.

    FAQ > How do I... (Level 1) > Stop my Windows Console from disappearing everytime I run my program?
    FAQ > How do I... (Level 1) > How do I get my program to wait for a keypress?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269
    You should use std::cin.get() instead of system.
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Or just run the program from the command prompt . . . or just read Dave's FAQ links (especially the second one).
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 07-13-2008, 08:16 PM
  2. Replies: 5
    Last Post: 10-25-2007, 12:27 PM
  3. Dev-C++ Compile and Run with Pause
    By xmltorrent in forum C++ Programming
    Replies: 12
    Last Post: 03-29-2006, 11:55 PM
  4. Replies: 4
    Last Post: 11-14-2001, 10:28 AM