Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   C++ (https://www.askmehelpdesk.com/forumdisplay.php?f=439)
-   -   How do I get it to stay on screen (https://www.askmehelpdesk.com/showthread.php?t=116778)

  • Aug 5, 2007, 01:35 PM
    albear
    How do I get it to stay on screen
    OK, I've written this programme and I've compiled it but when I run it I enter some numbers and words then I have to press enter to get there but as soon as it displays it it closes how can I make it so it doesn't do that
  • Aug 5, 2007, 03:37 PM
    albear
    Hello
  • Aug 6, 2007, 08:09 AM
    albear
    Anybody there
  • Aug 6, 2007, 09:47 AM
    asterisk_man
    At the end of your code output something like "press enter to quit" and then read in one more character. This way you'll wait for the user to do something before the program terminates.
  • Aug 6, 2007, 03:58 PM
    albear
    I've tried that but it still closes after I put my information in then press enter to continue but it just goes dtraight to the end of the programme then closes in an instant
  • Aug 6, 2007, 05:55 PM
    asterisk_man
    No, put the "press enter to continue" as the very last thing in main()
  • Aug 7, 2007, 03:37 PM
    albear
    I put a code in which I was told coded for that just before the Return 0, could you give me an example of the code you mean
  • Aug 8, 2007, 02:32 PM
    albear
    This is the bit I put it

    Cout << "Press Enter to exit";
    Cin.ignore(std::cin.rdbuf()->in_avail() + 1);
  • Aug 10, 2007, 07:00 AM
    albear
    Any advice would be great
  • Aug 10, 2007, 05:45 PM
    asterisk_man
    I'm not sure what it is you're trying to do with the second line you listed. I've not used iostream in a while but I think something like this will work:

    Code:

    char junk;
    cout << "Press Enter to exit" << endl;
    cin >> junk;

  • Aug 11, 2007, 07:36 AM
    albear
    Quote:

    Originally Posted by asterisk_man
    i'm not sure what it is you're trying to do with the second line you listed. i've not used iostream in a while but i think something like this will work:

    Code:

    char junk;
    cout << "Press Enter to exit" << endl;
    cin >> junk;


    OK it stays on screen after I put the information in but it doesn't close after I press enter, the line that you said you wernt sure on it has that line in the book and its worked before to make my text stay on screen
  • Aug 14, 2007, 06:20 AM
    asterisk_man
    If you're really stumped you can always fall back on plain c and use stdio.h
    Code:

    getchar();
  • Aug 14, 2007, 06:35 PM
    Nosnosna
    Cin >> tempchar; will only work if you actually give it a character to read... just pressing return won't advance the program.

    If, instead, you use cin.get(tempchar); it will behave the way you want.

  • All times are GMT -7. The time now is 05:20 PM.