Results 1 to 12 of 12

Thread: C++ newbie question

  1. #1
    Guest
    Ok, so I am just learning C++, don't get annoyed. I just want to know why this ends right away and doesn't stay in dos mode when I compile and run it in C++.

    Code:
    #include <iostream.h>
    int main()
    {
      cout<<"Hello World!";
    }
    Ask a stupid question, get a stupid answer.


    Thanks

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    The code outputs to a console window, which I thin kit slightly different to a DOS window. Anyway, that's just what happens when your code has finished executing. In the MSVC++6 IDE it waits for you to press a key when you've finished, but that's just for testing purposes.
    Harry.

    "From one thing, know ten thousand things."

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Open up command.com and run it from the command line. Alternatively, #include <stdlib.h>, and put system("pause"); at the end of your program.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728

    Thumbs up Response

    You have declared 'main' to return an int, which is good coding practice, but you don't return anything! Change your code to the following:

    Code:
    #include <iostream.h>
    int main()
    {
      cout<<"Hello World!";
      
      //Now we return 0!
      return 0;
    
    }
    Also, when you compile, set the compile option to Win32 Release, as opossed to Win32 Debug. Hope this helps!

    Bye
    Digital-X-Treme
    Contact me on MSN Messenger: [email protected]

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

  5. #5
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341

    Or...

    You could put

    #include <iostream.h>

    void main()
    {
    cout << "Hello World!" << endl;

    char a;

    cout << "Press Any Key...";

    cin >> a;
    }

    Which should work, basically it waits for u to press a key before quitting.

  6. #6
    Fanatic Member
    Join Date
    Apr 2000
    Location
    Whats a location?
    Posts
    516
    Or...

    You could open a MS-DOS Prompt and run it by using

    cd YourFolder

    and then

    YourApp.exe


    That's what I did until I got bored of C++ since it seemed just like QBasic, but without the ease, so I moved on to Visual C++ which is more fun.
    Courgettes.

  7. #7
    Guest
    This should work.
    Code:
    #include <iostream.h>
    void main()
    {
        int a;
        cout << "Hello World!";
        cin >> a;
    }

  8. #8
    Guest

    Thumbs up Thanks everyone!

    All your information has helped me much.

    I think I am going to like C++ .

  9. #9
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You will...it's a nice language. It's not perfect (some parts of C++ are a bit vile), but it's damn good for what it gives you.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  10. #10
    Guest

    Re: Response

    Originally posted by [Digital-X-Treme]
    You have declared 'main' to return an int, which is good coding practice, but you don't return anything! Change your code to the following:

    Code:
    #include <iostream.h>
    int main()
    {
      cout<<"Hello World!";
      
      //Now we return 0!
      return 0;
    
    }
    Also, when you compile, set the compile option to Win32 Release, as opossed to Win32 Debug. Hope this helps!

    Bye
    By the way, what does return 0; do?

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169

    Wink Why post twice?

    The return keyword returns the specified value, and exits the function. In C/C++, returning 0 from main indicates success.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  12. #12
    New Member
    Join Date
    Oct 2000
    Posts
    5
    Originally posted by V(ery) Basic
    That's what I did until I got bored of C++ since it seemed just like QBasic, but without the ease, so I moved on to Visual C++ which is more fun.
    That is the SINGLE most IDIOTIC reason I have EVER heard for not learning 'standard' C++...And gee...I wonder why Qbasic is like it...

    p.s. Visual C++ is gay. :)

Posting Permissions

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



Click Here to Expand Forum to Full Width