LoL....stupid newb needs help with Hello world.

This is a discussion on LoL....stupid newb needs help with Hello world. within the C++ Programming forums, part of the General Programming Boards category; Hi I have just started programming, but I have a problem with my hello world program....I recall fixing this at ...

  1. #1
    Unregistered
    Guest

    LoL....stupid newb needs help with Hello world.

    Hi I have just started programming, but I have a problem with my hello world program....I recall fixing this at one point, but I cannot figure it out now. The thing is whenever I execute the program, It comes up in the dos window, and then goes away again. I tried the ("PAUSE") function, but to no avail. Any advice?

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Did you try ("pause") ? If so that is incorrect. The correct usage is :

    system( "pause" );

    Also, you could use getch( ); for the last line in your code. I think you need to include conio.h for that.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Common problem. There's like 3 people a day with that question in the DOS forum.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    305
    i answered this question twice just today.

  5. #5
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    just use cin.get();

    put that like this
    Code:
    #include <iostream.h>
    
    int main()
    {
        cout << "Hello World, press enter to exit";
    
        cin.get();
        return 0;
    }
    What is C++?

  6. #6
    Registered User NewbieVB's Avatar
    Join Date
    Apr 2002
    Posts
    41

    Arrow

    whats that cin.get(); thing do?

  7. #7
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    yup its the same (almost) as getch(); but its in iostream.h so no extra headers
    What is C++?

  8. #8
    Registered User
    Join Date
    Feb 2002
    Posts
    591
    One is C and the Other is C++ and that is a huge difference. Try to only use one lang at the time because they are not the same. It will save you alot of trouble and your layout and coding style will look sharper if you don't mix and match the two at will.

  9. #9
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    WHY THE HELL DO YOU GUYS USE THESE KIND OF SUBJECT.. I AM A NEWBE ETC ETC.. IT IS SO SICK

  10. #10
    Registered User Mario's Avatar
    Join Date
    May 2002
    Posts
    317
    1. Self-pity
    2. Self-flagellation
    3. Trying to produce tears on someone that could potentially reply and actually stop and take a second look and after a nice, relieaving sigh (the likes of "thank god I don't live on that part of the world") produce the reply that was so sought after by the initial poster?

    Nah!...

    That subject line is a product of... fear.
    Since they don't bother to read the FAQ or use the search engine, they think a display of weakness (like a wolf showing his belly to the other wolf attacking him) can help them getting their answer without the flame that usually follows when people don't understand what it means to have a question being asked 1000th times...

    Off course, since people keep replying to that question, they are right.
    Regards,
    Mario Figueiredo
    Using Borland C++ Builder 5

    Read the Tao of Programming
    This advise was brought to you by the Comitee for a Service Packless World

  11. #11
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by Vicious
    yup its the same (almost) as getch(); but its in iostream.h so no extra headers
    Actually, it's not the same.

    cin.get();

    Echoes to the screen
    Allows the user to input a string
    Allows manipulation of the inputted string (backspace, delete)
    Returns only when ENTER has been pressed

    getch();

    Does NOT echo to the screen
    Only allows the user to input one single character
    Returns after any character has been pressed

    If you want to do a "Press any key to continue", cin.get(); would be very impractical. plus, it allows the user to "print garbage" on the screen even if that wasn't the intention. To a newb-program, this might not affect things too much, but in more "serious" programs it will...
    The only problem with getch() is that it's not ANSI C...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  12. #12
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    sigh... sorry... i didnt mean EXACTLY THE SAME! To us n00bs there is not that much of a difference. In our tiny little program they both are used to do the same thing... just to get the flippin program to stay there so we can see it..
    What is C++?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 05:39 PM
  2. OpenGL coordinates
    By Da-Nuka in forum Game Programming
    Replies: 5
    Last Post: 01-10-2005, 11:26 AM
  3. 'Hello World' - window disappears as soon as I run.
    By GandyCobra in forum C Programming
    Replies: 16
    Last Post: 09-15-2004, 12:38 PM
  4. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 01:51 PM
  5. Religious Bull****
    By Witch_King in forum A Brief History of Cprogramming.com
    Replies: 119
    Last Post: 10-23-2001, 08:14 AM

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