C/C++ What could be causing my program to hang on cin.getline() in C++ code?

  • Thread starter Thread starter yungman
  • Start date Start date
  • Tags Tags
    C++ Code
Click For Summary
The program hangs on `cin.getline()` due to improper use of `cin.ignore()`, which is intended to clear the input buffer. When `cin.ignore()` is called without arguments, it can lead to unexpected behavior if the buffer is empty, causing the program to hang. The user incorrectly assumes that placing `cin.ignore()` before every `cin.getline()` is necessary, but this can disrupt the flow of input. Debugging efforts are ineffective as the program does not return from the `cin.ignore()` call. Proper understanding of `cin.ignore()` and its parameters is essential to avoid these issues.
  • #31
Mark44 said:
I don't think this is a misconception.
I know. I was practicing being very polite and tactful :smile:
 

Similar threads

  • · Replies 36 ·
2
Replies
36
Views
4K
  • · Replies 66 ·
3
Replies
66
Views
5K
  • · Replies 75 ·
3
Replies
75
Views
6K
Replies
2
Views
2K
  • · Replies 14 ·
Replies
14
Views
34K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 17 ·
Replies
17
Views
2K