[問題] 同一變數有可能為字元或整數?
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Xcode 3.2.6
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
想要在要求輸入時
若輸入整數就進行後面的程式
若是任意字元就跳出結束程式
餵入的資料(Input):
可能是int或char
預期的正確結果(Expected Output):
1. Input (or 'q' to exit): 1
Hello, World!
Input (or 'q' to exit): (如此循環....)
2. Input (or 'q' to exit): q
Existing... (然後就跳出)
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版)
補充說明(Supplement):
由於一開始預期輸入整數,後面要做一些數字處理
所以把輸入的變數宣告為int
但是又想到若是輸入字元就可結束程式
就不知道要用怎樣的變數型態了
由於初學C++
還希望大家不吝指教
謝謝~~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.163.51.230
→
12/07 00:08, , 1F
12/07 00:08, 1F
→
12/07 00:08, , 2F
12/07 00:08, 2F
→
12/07 02:22, , 3F
12/07 02:22, 3F
→
12/07 03:29, , 4F
12/07 03:29, 4F
→
12/07 03:31, , 5F
12/07 03:31, 5F
→
12/07 09:59, , 6F
12/07 09:59, 6F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章