Thread: C++ quickness, please help :)

  1. #16
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Quote Originally Posted by limitedmage
    include this line at the top of the program:

    Code:
    #include <conio.h>
    and this line at the end of main, before return 0; :

    Code:
    getch();
    This may be the worst advice I've ever seen, today... let's take a simple program that should easily be standard and make it non-standard. To the OP, don't listen to this advice, it may work for you temporarily but it certainly will not work for everyone. Make sure your posting your exact code and we'll fix this the *standard* way.
    Sent from my iPadŽ

  2. #17
    Registered User
    Join Date
    Jul 2006
    Posts
    28
    why dont you just

    int blank;
    cin >> blank;

    before the return line?

  3. #18
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Because the user would then have to enter a digit or character instead of just hit the enter key on their keyboard.

    The solution was already given on post #2. Which is quiet extraordinary considering we are on post #18.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #19
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    As we're giving about 16 different alternatives, you could (not saying you should), use a system("pause"); but as Mario F (When's it gonna be ready?) said, post 2 is the best solution! Some more alternatives here

  5. #20
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Your problem is that there is more that just a newline sitting in the input buffer. Try this:
    Code:
    cin.clear();
    cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
    cin.get();
    From http://cboard.cprogramming.com/showthread.php?t=82179

    getch() works because it doesn't use the standard input stream, but rather ignores stdin and waits for a character to be pressed. It's a non-standard function and you shouldn't use it if you can help it.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #21
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> Your problem is that there is more that just a newline sitting in the input buffer.

    Perhaps, although the posted code doesn't even have any input.

  7. #22
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Maybe that wasn't all of the code. I can't think of any other reason why post #2's solution wouldn't work and getch() would. I should have said "I think your problem is . . .".
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed