Thread: Problem with Hello World program

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    1

    Problem with Hello World program

    Yep, new guy on the path of C++

    I'm using Dev C++

    Code:
    // a simple "Hello World" program!
    
    #include <iostream>
    
    int main()
    
    {
        std::cout << "Hello World!" << std::endl;
        return 0;
    }
    It compiles it, but when I run it nothing happens. I've tried the system pause command aswell, when I tried it a black console came up, but then went away a second later.

    Correct me if I'm wrong but is there something that can wait until you've pressed a key hen disappear?

    Thanks

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    10
    Code:
    // a simple "Hello World" program!
    
    #include <iostream>
    
    int main()
    
    {
        std::cout << "Hello World!" << std::endl;
    	while(1){}
        return 0;
    }
    i'm not an expert. the while loop should pause the program.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    A while loop is a very bad thing™, because it will consume 100&#37; cpu on one core.
    There are a few ways to solve this.
    - Use a debugger and put a breakpoint.
    - Add cin.get() add the end.
    - Use an IDE that has the option to keep the console open after the program ends (Visual Studio, for example).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I have finished my program, one problem
    By sloopy in forum C Programming
    Replies: 4
    Last Post: 11-29-2005, 02:10 AM
  2. Program problem
    By Birdhaus in forum C++ Programming
    Replies: 6
    Last Post: 11-21-2005, 10:37 PM
  3. Some Problem With My Program
    By Americano in forum C Programming
    Replies: 5
    Last Post: 10-18-2003, 01:58 AM
  4. Problem with Program not Quitting
    By Unregistered in forum Windows Programming
    Replies: 20
    Last Post: 06-11-2002, 11:06 PM
  5. Console Program Problem
    By Breach23 in forum C++ Programming
    Replies: 3
    Last Post: 10-19-2001, 12:35 AM