Hello. If you enter the wrong data in the code, for example, two words through a space, then the input is looped, the loop works and is not blocked where the "cin >> id >> name" instruction. This bug occurs on Linux and on Windows everything is correct. Tell me please what's the matter?
I'm not entirely sure why yours didn't work, but apparently in_avail() doesn't necessarily tell you how many characters are in the input (at least not on linux).
The replacement code works since instead of reading a specific number of characters, it just reads characters until it reads the newline.