Results 1 to 13 of 13

Thread: Dev C++ and troubles?

  1. #1
    Join Date
    Dec 2007
    Location
    Canada
    Posts
    187
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Dev C++ and troubles?

    ok I am using Dev C++ I am just getting into C++ and im wondering if this is any good?????

    and second I am running through a great TUT but whenever I run the code that I make it quickly flashes the command promp. and my code is saved compiled and made into executable format. it just always flashes the cmd and closes. I was wondering WHY?????

    EDIT: YAY!!!!! thanks to wizzup? from another post I found out what the problem was. im gonna post what to do and keep this for other noobs to read!!!!!!

    after your cout just insert

    int f;
    cin >> f; //This makes it so that when you type any key and press enter it closes!

    Hope this helps anybody else that encounters this error.
    I'm baaaack

  2. #2
    Join Date
    Dec 2007
    Location
    Somewhere in Idaho
    Posts
    480
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    For any that are interested, what is happening is the system opens a console window, preforms the output, then closes the console one the output is done. By putting the input there you stop the console window from closing instantly.

    Often, a better solution is to use system("PAUSE"); (I believe it is in the stdlib.h header) rather then cin >> some variable. There are some reasons for this. One is that cin doesn't provide buffer overflow protection. Many a malicious bug plays on this fact. While at the end of a short program might not be a big deal, it is a bad practice that you don't want to be in the habit of doing (if you want to pause your script that is)

  3. #3
    Join Date
    Feb 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by boberman View Post
    For any that are interested, what is happening is the system opens a console window, preforms the output, then closes the console one the output is done. By putting the input there you stop the console window from closing instantly.

    Often, a better solution is to use system("PAUSE"); (I believe it is in the stdlib.h header) rather then cin >> some variable. There are some reasons for this. One is that cin doesn't provide buffer overflow protection. Many a malicious bug plays on this fact. While at the end of a short program might not be a big deal, it is a bad practice that you don't want to be in the habit of doing (if you want to pause your script that is)
    I don't agree, doing a system("PAUSE"); is like bringing in a bulldozer to move a basketball.
    Current Project: Catching up on what I missed, re-writing some old includes I done in the past.
    Upcoming Project: Open For Suggestions

  4. #4
    Join Date
    Dec 2007
    Location
    Somewhere in Idaho
    Posts
    480
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Seroko View Post
    I don't agree, doing a system("PAUSE"); is like bringing in a bulldozer to move a basketball.
    Yeah, but putting a cin >> blah is just begging for a buffer overflow. Yeah, its at the end of a program, but still it isn't a good idea to end your programs with a segfault

  5. #5
    Join Date
    Jan 2007
    Location
    Kansas
    Posts
    3,760
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    Last time I checked, system("PAUSE") doesn't work on every OS


  6. #6
    Join Date
    Aug 2006
    Location
    London
    Posts
    2,021
    Mentioned
    2 Post(s)
    Quoted
    0 Post(s)

    Default

    i doubt you'll have the problem of a closing cmd window in a non-windows OS

    i support the system("pause")
    sometimes i do this, cause on linux its not needed
    Code:
    #ifdef __WIN32__
    system("pause");
    #endif
    Join the Official SRL IRC channel. Learn how to Here.

  7. #7
    Join Date
    Feb 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    system("pause"); is such a crazily wasteful function look at what it does:

    1. suspend your program
    2. call the operating system
    3. open an operating system shell (relaunches the O/S in a sub-process)
    4. the O/S must now find the PAUSE command
    5. allocate the memory to execute the command
    6. execute the command and wait for a keystroke
    7. deallocate the memory
    8. exit the OS


    resume your program
    Current Project: Catching up on what I missed, re-writing some old includes I done in the past.
    Upcoming Project: Open For Suggestions

  8. #8
    Join Date
    Dec 2007
    Location
    Somewhere in Idaho
    Posts
    480
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Seroko View Post
    system("pause"); is such a crazily wasteful function look at what it does:

    1. suspend your program
    2. call the operating system
    3. open an operating system shell (relaunches the O/S in a sub-process)
    4. the O/S must now find the PAUSE command
    5. allocate the memory to execute the command
    6. execute the command and wait for a keystroke
    7. deallocate the memory
    8. exit the OS


    resume your program
    Ok, how many times will it be called? once? The only reason this function is used is to stop the output at the end of a program to allow the programmer to analyze what is outputted. So it adds an extra *GASP* 100k onto the memory, You know what, I think any computer built in the last 15 years can handle that. Now if you are programming for a Pentium 1 76 mhz processor with 32k of memory, then you might have a point. But if that is the case you wouldn't even be using C++.

    Im sorry, but a single call to a wasteful function who's entire purpose IS TO STOP THE PROGRAM doesn't seem all that bad to me. So cin stops your program that much faster Whoopty doo. I'm sure I could come up with an assembly version of that would stop the program even faster.

    Seriously, this is a function that stops a program, Who cares how efficiently it brings the program to a screeching halt? You can't have multiple instances of this function (Well you could, but why on earth would you be calling multiple programming stopping functions?), so the memory it uses is minute. And again, it will be called 99% of the time a grand total of 1 time per program. For beginning programmers, I don't see that as being a big problem. More advanced programs have little need for the user to halt the console so user can read the output. (because they are often doing much more then outputting text to a console).

  9. #9
    Join Date
    Nov 2006
    Posts
    235
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by insanomano View Post
    ok I am using Dev C++ I am just getting into C++ and im wondering if this is any good?????

    and second I am running through a great TUT but whenever I run the code that I make it quickly flashes the command promp. and my code is saved compiled and made into executable format. it just always flashes the cmd and closes. I was wondering WHY?????

    EDIT: YAY!!!!! thanks to wizzup? from another post I found out what the problem was. im gonna post what to do and keep this for other noobs to read!!!!!!

    after your cout just insert

    int f;
    cin >> f; //This makes it so that when you type any key and press enter it closes!

    Hope this helps anybody else that encounters this error.
    Ignore the argument going on and use system("pause");

    And with Dev C++, you don't need any additional includes to do it.
    If I see you autoing with level 3/default clothes/crap name I WILL report you. Auto Correctly. - put this in your sig
    http://www.stats.srl-forums.com/sigs/5612.png
    http://www.wizards.com/magic/images/...or_iswhite.jpg

  10. #10
    Join Date
    Feb 2007
    Posts
    211
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    The point is to get people to not be in the habit of using System("pause"); I agree it serves he purpose when testing but if you are calling it fairly often you are wasteful. Its more to not to get into the habit of doing it then anything, so please don't make rude comments because you disagree, google it. Theres thousands of documents that will tell you the exact same thing.
    Current Project: Catching up on what I missed, re-writing some old includes I done in the past.
    Upcoming Project: Open For Suggestions

  11. #11
    Join Date
    Dec 2007
    Location
    Somewhere in Idaho
    Posts
    480
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Seroko View Post
    The point is to get people to not be in the habit of using System("pause"); I agree it serves he purpose when testing but if you are calling it fairly often you are wasteful. Its more to not to get into the habit of doing it then anything, so please don't make rude comments because you disagree, google it. Theres thousands of documents that will tell you the exact same thing.
    actually, there are two articles, and yes I have read them both. But based on the system("pause"); arguments, we should never use, VB, C#, java, python, perl, php, ect because they have extra libraries they have to load and that takes memory and time making them "slow". Sorry, but there is a reason these languages exist and have gained popularity, its because computers have gotten fast enough.

    Even overused, the fact still remains, the purpose is to completely stop the program. Oh crap, I just wasted 5 processor cycles to stop my program when I could have stopped it in 2. That has degraded my CPU by 0.000000000001 second....

    Please don't make uninformed comments based on the first page you googled. Rather, make an informed opinion about something. I didn't insult you at all in my previous post, so if you found that offensive I apologize. However, I don't in anyway conceed that what you are saying is a valid argument, because it isn't. Because what you are saying is that system("pause") makes your programs slower (less efficient as you put it), Well duh, that is kind of the point. Not only that, but 1000 calls to system("pause") wont increase the memory footprint of your program any more then one call will. It adds maybe a couple of bytes onto your program for each time you call it.

    BTW, on the first link the argument about the increase in executible size because of the added <cstdlib> is laughable at best. generic C++ program without any includes.. 3.0kb With cstdlib and system("pause"); 3.3kb. Yeah, that .3 kb is just going to kill a lot of people.

  12. #12
    Join Date
    Aug 2006
    Location
    London
    Posts
    2,021
    Mentioned
    2 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Seroko View Post
    system("pause"); is such a crazily wasteful function look at what it does:

    1. suspend your program
    2. call the operating system
    3. open an operating system shell (relaunches the O/S in a sub-process)
    4. the O/S must now find the PAUSE command
    5. allocate the memory to execute the command
    6. execute the command and wait for a keystroke
    7. deallocate the memory
    8. exit the OS


    resume your program

    i can also use google

    "premature optimization is the root of all evil"
    Join the Official SRL IRC channel. Learn how to Here.

  13. #13
    Join Date
    Aug 2008
    Location
    Planet Earth.
    Posts
    53
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Code:
    for(;;) std::cin.get();
    Ftw.
    Learning: Italian!
    Code:
    <Jason2G's> I just sprayed WD-40 on my dog's nuts. He was sleeping. And now he can't get back to sleep ^_^

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Troubles with script help please
    By aamimi in forum OSR Help
    Replies: 3
    Last Post: 08-26-2008, 06:14 PM

Posting Permissions

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