Wait until user presses enter in C++?

前端 未结 3 1740
难免孤独
难免孤独 2020-12-21 17:50
waitForEnter() {
    char enter;

    do {
        cin.get(enter);
    } while ( enter != \'\\n\' );
}

It works, but not always. It doesn\'t work w

3条回答
  •  一生所求
    2020-12-21 18:09

    (the first parameter) The name of the array of type char[] in which the characters read from cin are to be stored.

    (the second parameter) The maximum number of characters to be read. When the specified maximum has been read, input stops.

    (the third parameter) The character that is to stop the input process. You can specify any character here, and the first occurrence of that character will stop the input process.

    cin.getline( name , MAX, ‘\n’ );
    

    Page 175 IVOR HORTON’S BEGINNING VISUAL C++® 2010

提交回复
热议问题