更新时间:2023-02-05 11:39:31
当用户输入时,输入code> cin.getline 索引,他们也键入换行符,但您的cin没有从输入流中删除它。因此,您对cin.getline的调用将因为剩余的换行符而立即返回。
When the user entered the index, they also typed a newline, but your cin didn't remove it from the input stream. So, your call to cin.getline returns immediately because of the leftover newline.
添加对 cin.ignore 之前,cin.getline将其刷新。
Add a call to cin.ignore before the cin.getline to flush it out.