Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

press enter to continue (c++)

  • 22-05-2002 12:17pm
    #1
    Closed Accounts Posts: 5


    hey ppl's,

    got a small prob.

    some code,

    do{
    cout << "Press enter to continue";
    string response; // char response;
    cin >> response;
    }while(response == "\n") // response == '\n'

    wot it needs to do:
    1. displays press enter to continue
    2. person presses enter.
    3. loop continues.

    my prob seems to be with \n.

    any suggestions??


Comments

  • Closed Accounts Posts: 358 ✭✭CH


    getch()

    ?


  • Registered Users, Registered Users 2 Posts: 2,781 ✭✭✭amen


    you should check for the prescence of the actucal ascii code for carriage return. i think its 13 along with CHs suggestion


  • Registered Users, Registered Users 2 Posts: 1,393 ✭✭✭Inspector Gadget


    ...bear in mind that "\n" is a short-code used pretty much exclusively by printf and the likes; if you want to see whether return has been pressed, you need to either use getch() to scan one character at a time or use cin and scan "response" (a loop or something), but either way, "\n" will be construed as two characters, and therefore two ASCII values (92 and 110 decimal, I think, or 0x5C and 0x6E hex) instead of a single carriage return (usually abbreviated CR) - as mentioned, ASCII 13 (decimal) or 0x0D (hex).

    Gadget


  • Registered Users, Registered Users 2 Posts: 14,149 ✭✭✭✭Lemming


    could be lazy and use the following
    system("pause") ;
    

    but afaik, only using windoze


  • Closed Accounts Posts: 5 angelr


    thanks ppl.

    the function i needed was getchar().
    thnx CH.

    also jus for ye's own info.
    If i were to use the second option of checking the ASCII character.
    i wud of needed to change from cin to getline(cin, variable).
    Cos cin demands that ya enter sumthing whereas getline doesnt.

    all these code work perfectly in the sample i gave ye's.
    the bizarre thing is that it doesnt work when i put it into the actualy code i need it for. more hair pulling out time. :-)

    if i were coding for windoze i wud hav used ur suggestion Lemming. thnx anyways.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,722 ✭✭✭Thorbar


    When you use g++ in linux whenever the output is going to be bigger then the current terminal window it automatically asks for the user to hit enter and scrolls threw the output. Really nice feature. In windows just use system("PAUSE") and include cstdlib.h.


Advertisement