開發平台(Platform):C++(QT)
問題(Question): 利用stringstream 進行string to int 的多載問題
餵入的資料(Input):int string
程式碼(Code):(請善用置底文網頁, 記得排版)
string quit,check;
stringstream quittem;
int number;
cin>>quit;
quittem<<quit;
quittem>>check;
quittem>>number;
if(check=="c")
cout<<check<<endl;
else
number++;
quittem.clear();
quittem.str("");
補充說明(Supplement):
從網路上我學習到了利用stringstream來進行string轉int,double等數字
但目前我想要有一個功能是,藉由cin來偵測我按的按鈕
比方說 我按C,cout出程式結束,但如果按的是數字,
能接這此數字直接接下去做運算
上面程式碼是我為了要表達我的問題而建立的簡易程式碼
我的疑問及在於
quittem>>check;
quittem>>number;
是不被允許的,想問不允許的原因
以及是否能有辦法利用strinstream達到此功能
亦或是有其他方法,能供我學習
謝謝