Extreme Newbie

This is a discussion on Extreme Newbie within the C++ Programming forums, part of the General Programming Boards category; I am extremly new to C++ (I started about an hour ago). I learned how to make the "hello world" ...

  1. #1
    TheMetsAreBad
    Guest

    Question Extreme Newbie

    I am extremly new to C++ (I started about an hour ago). I learned how to make the "hello world" file, but I want to know how to keep it open (because it closes automatically).

    So far, I have:



    #include <iostream.h>

    int main()
    {
    cout << "Hello world!" << endl;
    return(0);
    }


    Can someone please tell me the code to keep the window open?

    Thanks

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    A) use code tags like illustrated in B.

    B)
    Code:
    #include <iostream.h>
    #include <stdlib.h>
    
    int main()
    {
    cout << "Hello world!" << endl;
    system("pause");
    return(0);
    }
    C) the mets are just playin with the competition thus far

  3. #3
    Geo Geo Geo-Fry
    Join Date
    Feb 2003
    Posts
    116
    1. Use [c0de] and [/c0de] tags
    2. Read the FAQ, its in there
    3. Use specific topic titles
    4. There are tons of things you can do, I use
    Code:
    #include <string>
    ...
        system("Pause");
        return 0;
    But that is partially compiler dependent

    <edit>jamsan, i hate you</edit>
    <edit2>ur name should be JAMSTUPID. AHJAHAHAHAHA!!!</edit2>
    Last edited by Geo-Fry; 05-13-2003 at 07:47 PM.
    "You can lead a man to Congress, but you can't make him think."
    "The Grand Old Duke of York
    -He had ten thousand men.
    -His case comes up next week."
    "Roses are red, violets are blue, I'm schizophrenic, and so am I."
    "A computer once beat me at chess, but it was no match for me at kick boxing."
    "More and more of our imports are coming from overseas."
    --George W. Bush
    "If it weren't for electricity, we'd all be wacthing TV by candlelight."
    --George W. Bush

  4. #4
    The Pantless Man CheesyMoo's Avatar
    Join Date
    Jan 2003
    Posts
    262
    I assume you're using a console considering that happens.

    You have a coouple of choices, you can include <conio> and use the getch() funtion:
    Code:
    #include <iostream>
    #include <conio>
    using namespace std;
    
    int main()
    {
       cout << "Hello, world!" << endl;
       getch();
       return 0;
    }
    // The getch function pauses the program until a key is pressed.
    I think you can also use the <iostream> member function get() to pause, I'm no so sure about that though.
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
       cout << "Hello, world!" << endl;
       cin.get();
       return 0;
    }
    Hope that helps, have fun, and don't give up!

    Edit: Dangit I got beaten, oh yeah Geo-Fry, I don't think that you should use 1337 in the code tags...
    If you ever need a hug, just ask.

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    Originally posted by Geo-Fry
    <edit2>ur name should be JAMSTUPID. AHJAHAHAHAHA!!!</edit2>
    both pieces of code work there chief...dont be jealous

  6. #6
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    try taking out the return part... what compiler are you using?
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  7. #7
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    Originally posted by major_small
    try taking out the return part... what compiler are you using?
    Genious. Pure genious.

  8. #8
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Originally posted by Jamsan
    A) use code tags like illustrated in B.

    B)
    Code:
    #include <iostream.h>
    #include <stdlib.h>
    
    int main()
    {
    cout << "Hello world!" << endl;
    system("pause");
    return(0);
    }
    C) the mets are just playin with the competition thus far
    lovely how you show code tags with no indentation.

  9. #9
    Registered User dragon_man's Avatar
    Join Date
    May 2003
    Posts
    6
    What does the
    Code:
    using namespace std;
    Thing mean

  10. #10
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511

    Smile

    What does the
    code:--------------------------------------------------------------------------------using namespace std;--------------------------------------------------------------------------------
    Thing mean
    This question has been answered before!!!! Look around at sources to find the answer.
    Mr. C: Author and Instructor

  11. #11
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    check the FAQ. Many of the questions in this thread will be found in there.

  12. #12
    TheMetsAreBad
    Guest
    Thanks everyone! It works!

  13. #13
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Originally posted by Jamsan
    Genious. Pure genious.
    hey... i've never had this problem before... the window always stays open unless i close it...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  14. #14
    1.b4 e5 2.a3 d5 3.d4 exd
    Join Date
    Jan 2003
    Posts
    167
    If u open it in command prompt itll stay open, but if u open it as an executable itll close when its finished unless u program it not to.
    AIM: MarderIII

  15. #15
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355
    Also VC++ (dunno about any others) adds a pause at the end of programs in debug build automatically, but not in release build.
    Thor's self help tip:
    Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.

    OS: Windows XP
    Compiler: MSVC

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 18
    Last Post: 11-04-2005, 02:41 PM
  2. Replies: 2
    Last Post: 12-09-2004, 02:59 PM
  3. Extreme newbie need help Installing Slackware 10.0
    By axr0284 in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 12-09-2004, 01:46 PM
  4. extreme newbie
    By sreetvert83 in forum C++ Programming
    Replies: 12
    Last Post: 03-31-2003, 06:36 PM
  5. extreme newbie
    By sreetvert83 in forum Game Programming
    Replies: 2
    Last Post: 03-24-2003, 05:21 PM

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