[問題] cin.getline()如何做到重複輸入??

看板C_and_CPP (C/C++)作者 (費諾)時間13年前 (2013/03/16 17:19), 編輯推噓1(103)
留言4則, 2人參與, 最新討論串1/1
開發平台(Platform): VC++ 額外使用到的函數庫(Library Used): iostream 問題(Question):使用字元陣列,再使用cin.getline(),它就不能再重複執行了 餵入的資料(Input):feanor fingolfin hong, y, feanor hong 預期的正確結果(Expected Output):6 16, 6 錯誤結果(Wrong Output):6 16, 按任意鍵繼續 程式碼(Code):(請善用置底文網頁, 記得排版) #include<iostream> #include<string> using namespace std; int main() { char answer; do { int end; int counterblank = 0; int blank[2]; char initial[30]; system("cls"); cin.getline(initial,30); for(int j = 0;j<30;j++) { if(initial[j]==' ') { blank[counterblank] = j; counterblank++; } if(initial[j]=='\0') { end = j; } } if(counterblank==1) { for(int g =0;g<1;g++) { cout<<blank[g]; blank[g] = 0; } } else { for(int h = 0;h<2;h++) { cout<<blank[h]<<" "; blank[h] = 0; } } cout<<endl; cout<<"Do you want to do it again??(y/others)"<<endl; cin>>answer; }while((answer=='y')||(answer=='Y')); system("pause"); return 0; } 補充說明(Supplement): string 我之後會拿掉 -- 306 長官 , 恕我冒犯 ! 是標緻406 , 應該不是原廠的 白癡 我是說他的速度306 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 42.70.129.34

03/16 17:20, , 1F
先謝謝在板上的各位大大 感激不盡
03/16 17:20, 1F

03/16 17:23, , 2F
cin>>跟getline混用,要做ignore
03/16 17:23, 2F

03/16 17:25, , 3F
要怎麼做呢??
03/16 17:25, 3F

03/16 17:27, , 4F
我有頭緒了,謝謝~~
03/16 17:27, 4F
文章代碼(AID): #1HH3acWk (C_and_CPP)
文章代碼(AID): #1HH3acWk (C_and_CPP)