[問題] stringstream 多重載入詢問

看板C_and_CPP (C/C++)作者 (R大)時間11年前 (2014/12/26 06:08), 11年前編輯推噓1(103)
留言4則, 4人參與, 最新討論串1/1
開發平台(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達到此功能 亦或是有其他方法,能供我學習 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 190.115.188.139 ※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1419545336.A.9C5.html ※ 編輯: redonizuka (190.115.188.139), 12/26/2014 06:19:22

12/26 09:30, , 1F
將check字串轉數字不就好了?
12/26 09:30, 1F

12/26 09:59, , 2F
寫parser(無誤
12/26 09:59, 2F

12/26 10:51, , 3F
何苦... XD boost::lexical_cast轉轉看不就知道了
12/26 10:51, 3F

12/26 11:52, , 4F
c++11 std::stoi
12/26 11:52, 4F
文章代碼(AID): #1Kd8hud5 (C_and_CPP)
文章代碼(AID): #1Kd8hud5 (C_and_CPP)