Results 1 to 6 of 6

Thread: What I'm I doing wrong?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default What I'm I doing wrong?

    I've been trying to learn C++ and I've started with the clasic hello world program just as a test. But every time I try to run it the dos type window appears just for a fraction of a second. My code:

    Code:
    // hello world program
    
    #include <iostream>
    using namespace std;
    
    int main ()
    {
    	cout << "Hello World!";
    	return 0; }
    Does anyone see anything obvious?
    When it occurs to a man that nature does not regard him as important and that she feels she would not maim the universe by disposing of him, he at first wishes to throw bricks at the temple, and he hates deeply the fact that there are no bricks and no temples
    -Stephen Crane

  2. #2
    Senior Member Senior Member Reenk Roink's Avatar
    Join Date
    Oct 2005
    Posts
    4,353

    Default Re: What I'm I doing wrong?

    Your code looks OK, I really don't see the problem. Try putting the end curly on the next line like this:

    Code:
    // hello world program
    
    #include <iostream>
    using namespace std;
    
    int main ()
    {
    	cout << "Hello World!";
    	return 0; 
    }
    If that doesn't work, it may not be the code's fault but something else.

    Good luck learning by the way, I'm learning it too (and having a tough time in class).

  3. #3

    Default Re: What I'm I doing wrong?

    That didn't work.
    Good luck to you to, I've been trying off and on for about a year and now I'm trying to make a solid attempt. What compiler do you use?
    When it occurs to a man that nature does not regard him as important and that she feels she would not maim the universe by disposing of him, he at first wishes to throw bricks at the temple, and he hates deeply the fact that there are no bricks and no temples
    -Stephen Crane

  4. #4
    Honorary Argentinian Senior Member Gyroball Champion, Karts Champion Caius's Avatar
    Join Date
    Aug 2006
    Location
    I live in my home, don't you?
    Posts
    8,114

    Default Re: What I'm I doing wrong?

    Why you dont start from crash again?




    Names, secret names
    But never in my favour
    But when all is said and done
    It's you I love

  5. #5
    Senior Member Senior Member Reenk Roink's Avatar
    Join Date
    Oct 2005
    Posts
    4,353

    Default Re: What I'm I doing wrong?

    Quote Originally Posted by Destroyer of Hope
    That didn't work.
    Good luck to you to, I've been trying off and on for about a year and now I'm trying to make a solid attempt. What compiler do you use?
    I use the compiler that comes with Visual Studio 2005 (school software) but I don't know specifically.

    Also, one last thing. Caius Flaminius is right, just try again, and try adding an "endl;" after your cout like:

    Code:
    cout << "Hello World!" << endl;

  6. #6

    Default Re: What I'm I doing wrong?

    found the problem, the program wasn't stoping at the end so it just closed. I fixed it by adding: system (pause) to the end. Thanks for your help.
    When it occurs to a man that nature does not regard him as important and that she feels she would not maim the universe by disposing of him, he at first wishes to throw bricks at the temple, and he hates deeply the fact that there are no bricks and no temples
    -Stephen Crane

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Single Sign On provided by vBSSO