Need A little Help

This is a discussion on Need A little Help within the C++ Programming forums, part of the General Programming Boards category; I been using since I started programming in C++ is system("pause");. Some people are telling me that it is a ...

  1. #1
    Registered User Sshakey6791's Avatar
    Join Date
    Nov 2008
    Location
    -
    Posts
    57

    Question Need A little Help

    I been using since I started programming in C++ is system("pause");. Some people are telling me that it is a bad idea to use this and gave me some stuff to read and I see why... Not I started using cin.get() and someone else show me why that is bad so is there anything that I can use to pause my program that is not bad? thanks
    "Blood you have thirsted for -- now, drink your own!"
    (Dante)

  2. #2
    Registered User
    Join Date
    May 2006
    Posts
    903
    Why would cin.get() be bad ? I'm curious.

  3. #3
    Registered User Sshakey6791's Avatar
    Join Date
    Nov 2008
    Location
    -
    Posts
    57
    I don't know. They didn't really say it was bad but there was a better way.....
    "Blood you have thirsted for -- now, drink your own!"
    (Dante)

  4. #4
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,479
    cin.get(); is used in almost all program books that are to standard to teach console programming. system("pause"); is bad mainly due to it being unsafe. also calls to the system commands should be left to the CPU really.

    There are other system commands like time and date, but they are also bad, and they should only be used when you really have to. cin.get is perfectlu ok to use as a console pause function.

    Depending on your IDE, programs executed in non-debug mode will pause the console at the end for you. VC++ is one that does this.
    I'm just trying to be a better person - My Name Is Earl

  5. #5
    Registered User
    Join Date
    Dec 2008
    Posts
    65
    Like was said above, there are several IDEs that will automatically pause your program, Code::Blocks, VC++, and others. If it bothers you that much run your programs from the command prompt.

    Cheers!

  6. #6
    Registered User Sshakey6791's Avatar
    Join Date
    Nov 2008
    Location
    -
    Posts
    57
    I use VC++ But When I use the .exe file it close out without displaying the output but.... Thanks for the tips I going to try the Code::Blocks.
    "Blood you have thirsted for -- now, drink your own!"
    (Dante)

  7. #7
    Dae
    Dae is offline
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    system("pause"); also isn't apart of the C++ standard. It's windows specific.

    http://www.gidnetwork.com/b-61.html

    cin.get() is fine to use.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  8. #8
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,274
    Quote Originally Posted by Dae View Post
    system("pause"); also isn't apart of the C++ standard. It's windows specific.
    Well, system() is standard, but the string you pass it is not.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  9. #9
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    920
    I've gotten into the habit of toggling between a command line and my IDE. It sort of undermines the IDE, but for some things (viewing output, passing arguments that change a lot) it can be quicker.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,033
    Quote Originally Posted by Sshakey6791 View Post
    I use VC++ But When I use the .exe file it close out without displaying the output but.... Thanks for the tips I going to try the Code::Blocks.
    Debug -> Start without debugging.
    Window won't disappear.
    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.

  11. #11
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Quote Originally Posted by Elysia View Post
    Window won't disappear.
    You got that right, best OS ever
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

Popular pages Recent additions subscribe to a feed

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