Menu

CANTI SEE THE OUTPUT WHEN I RUN A PROGRAM

Rocky
2010-02-15
2012-09-26
  • Rocky

    Rocky - 2010-02-15

    Hello guys,

    I am wondering if anyone can help me. I've just downloaded and installed this
    Dev-C++ and I wrote a simple C program then compile it . but when I want to
    run it, I dont see the output in DOS as it shuld be. Can anyone help me on how
    to configure this compiler to enable me to see the output in a DOS screen.

     
  • anonymous nobody

    C:

    getchar();
    

    C++:

    std::cin.ignore(2147483647, '\n');
    std::cin.get();
    

    The arbitrary-looking number is the standard limit to ignoring characters left
    in the input stream.

    Do NOT use this code:

    system("pause");
    

    It executes the first executable with the name "pause" found. Usually this is
    a system EXE that outputs "Press any key to continue..." and waits for a key.
    However, this is a massive security hole; one could edit the string "pause"
    with a command that causes serious harm to users.

     
  • cpns

    cpns - 2010-02-16

    First-time; don't post your question on BOTH forums!

    Drmoo:

    The arbitrary-looking number is the standard limit to ignoring characters
    left in the input stream.

    Yuk! What are you thinking!? No 'arbitrary' number needed; include <limits>
    then:

    cin.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );
    

    Do NOT use this code:

    The "pause" command is not an executable, it is built in to cmd.exe. Such code
    is generally a temporary kludge used during development; you'd hardly deploy
    using this, so the security issue is largely irrelevant. It is quick-and-
    dirty, but that is kind of the point here.

     
  • cpns

    cpns - 2010-02-16

    First-time; don't post your question on BOTH forums!

    I take that back; you didn't; my error, I managed to fail to post my original
    answer; whcih was along teh lines of:

    Having called your self "first time" it is ironic that you chose not to read
    the "PLEASE READ BEFORE POSTING A
    QUESTION
    "
    thread. Your problem is item (2) in the
    common problems list.

    However my view on this is that you should not be surprised. When a process
    terminates, Windows closes its window. This is normal and desirable behaviour,
    otherwise you'd have many dead windows left on your desktop waiting for you to
    manually close them. It is a wonder then that users are so often surprised
    when it happens to their own programs! If you want to see the output, don't
    let the process terminate until you ask it to via some kind of user input.

    Drmoo: You gave a C++ solution when first-time is writing C code.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.