[問題] 字串讀出unicode 編碼

看板C_and_CPP (C/C++)作者 (f814030買者會視接單數量)時間11年前 (2015/05/14 09:32), 11年前編輯推噓3(307)
留言10則, 4人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) bcb 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 請問各位先進, "犇" 這個字的編碼為:29319(10進位), 小弟在程式中用unicode string 接收了"犇"這個字, 但想要讀出 int 29319,請問該如何做呢? 煩請各位提點一下,謝謝。 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 211.72.118.19 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1431567122.A.AA4.html

05/14 09:57, , 1F
fscanf?
05/14 09:57, 1F

05/14 10:10, , 2F
在程式中用unicode string 接收了"犇"這個字 <-- 詳述
05/14 10:10, 2F
您好, 小弟長話短說,還請您見諒, bcb中 String 已經是unicode string 的型態,所以我將 String strTemp = L"犇"; 所以我在strTemp就可以看到unicode 編碼為:29319, 不過現在正想辨法要把 29319 寫到另一個int 的變數中。 ※ 編輯: f814030 (211.72.118.19), 05/14/2015 10:20:55

05/14 10:24, , 3F
你應該是要"rb"讀binary不是"rt"吧
05/14 10:24, 3F

05/14 10:26, , 4F
阿 看到了...原來有string strTemp這種東西 沒用過=_=
05/14 10:26, 4F

05/14 10:50, , 5F
(int)strTemp[1]
05/14 10:50, 5F
感謝Toby大大, 成功了! 請問為什麼要加[1] ? 先前有試過 int temp = (int)strTemp; 這樣子在'A' 這樣的字元是可以的,不過在unicode 就無用了… 為什麼要加[1] 啊 @@ 再次的感謝! ※ 編輯: f814030 (211.72.118.19), 05/14/2015 10:56:59

05/14 12:32, , 6F
1 是index,Unicode String在desktop上都是1-based,
05/14 12:32, 6F

05/14 12:32, , 7F
在mobile都是0-based
05/14 12:32, 7F

05/14 17:57, , 8F
然後Unicode String以[]operater每個元素都是wchar_t
05/14 17:57, 8F

05/14 17:58, , 9F
operator
05/14 17:58, 9F

05/14 18:00, , 10F
效果跟 strTemp.w_str()[0] 是一樣的
05/14 18:00, 10F
謝謝您! ※ 編輯: f814030 (211.72.118.19), 05/15/2015 14:13:50
文章代碼(AID): #1LK_iIga (C_and_CPP)
文章代碼(AID): #1LK_iIga (C_and_CPP)