My program closes immediately

This is a discussion on My program closes immediately within the C++ Programming forums, part of the General Programming Boards category; Hello everyone, I'm new to this forum and just started learning C++. I have Windows XP and my compiler is ...

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    2

    Question My program closes immediately

    Hello everyone,

    I'm new to this forum and just started learning C++. I have Windows XP and my compiler is Bloodshed DEV/C++ 4. I started the tutorial and tried to compile the first program. Once I opened the .exe file, it closes immediately, but if you're very fast, you can see that it does output 'Hello world!'. I really don't understand what went wrong, so I included the .cpp file. I hope that anyone could help me.

    Icewout_be.
    Attached Files Attached Files

  2. #2
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    You got to have something to make it stop for you to read the text. Include <cstdio> and right before you do your "return 0" add in getchar()

    Code:
    #include <cstdio>
    #include <iostream>
    
    int main()
    {
       std::cout<<"Hello, world!";
       getchar();
       return 0;
    }

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    FAQ
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Nov 2003
    Posts
    2

    Woohoo!

    Thank you very much! Now it works! I hope I'll become as good as you guys are!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. making a program leave a msg for background program when it closes
    By superflygizmo in forum Windows Programming
    Replies: 2
    Last Post: 02-06-2006, 06:44 PM
  2. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  3. program closes fast
    By MrSoy in forum C Programming
    Replies: 5
    Last Post: 04-10-2003, 08:00 PM
  4. program open and closes
    By Musicdip in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 06-27-2002, 04:34 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21