cin.getline沒有照預期執行 |
尚未結案
|
pslg
一般會員 發表:2 回覆:4 積分:1 註冊:2005-06-11 發送簡訊給我 |
[1]
#include |
Stallion
版主 發表:52 回覆:1600 積分:1995 註冊:2004-09-15 發送簡訊給我 |
你的問題在於第一次cin時所按的Enter字元還存在於緩衝區,其後被第二次getline直接接收了,改進方法如下:
void main(void) { cout<<"enter insert line==>\n"; int line_num; cin>>line_num; cin.get();//把enter字元從緩衝區移除 char insert[1000]; cout<<"enter insert context==>"<----------------------------------------------- Creation is the fundation of promotion. |
pslg
一般會員 發表:2 回覆:4 積分:1 註冊:2005-06-11 發送簡訊給我 |
引言: 你的問題在於第一次cin時所按的Enter字元還存在於緩衝區,其後被第二次getline直接接收了,改進方法如下:暸改啦,謝謝void main(void) { cout<<"enter insert line==>\n"; int line_num; cin>>line_num; cin.get();//把enter字元從緩衝區移除 char insert[1000]; cout<<"enter insert context==>"<----------------------------------------------- Creation is the fundation of promotion. |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |