getline() does not work if used after some inputs

haracters are extracted until either (n – 1) characters have been extracted or the delimiting character is found (which is delimiter if this parameter is specified, or ‘\n’ otherwise). The extraction also stops if the end of the file is reached in the input sequence or if an error occurs during the input operation.

When cin.getline() reads from the input, there is a newline character left in the input stream, so it doesn’t read your c-string. Use cin.ignore() before calling getline().

cout<<"Journal Entry:\t";
cin.ignore();
cin.getline(journal,23);

Leave a Comment