[問題] string array 轉為char array

看板C_and_CPP (C/C++)作者 (Talk to Her)時間15年前 (2011/04/29 16:06), 編輯推噓3(304)
留言7則, 3人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) BCB 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 我有一個十六進位的字串陣列,要將他轉成十進位後輸出 String output2[20]={"3104","503D","A79C",...}; 我是想用strtol轉成十進位後輸出 int dec[20]; for(i=0;i<20;i++){ dec[i]=strtol(output2[i],0,10); sgr->Cells[3][i+1]=IntToStr(dec[i]); } 可是他會出現Cannot convert'AnsiString' to 'const char'的Error 所以我想請問有什麼方法可以把string array 轉成char array嗎? 最近剛用BCB,還沒有很熟 程式碼(Code):(請善用置底文網頁, 記得排版) http://codepad.org/UZMHjF4F 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 211.74.192.147 ※ 編輯: jspout 來自: 211.74.192.147 (04/29 16:07) ※ 編輯: jspout 來自: 211.74.192.147 (04/29 16:08)

04/29 16:16, , 1F
output2[i].c_str()?
04/29 16:16, 1F

04/29 16:17, , 2F
google "c_str bcb string"
04/29 16:17, 2F

04/29 16:18, , 3F
還有你原來16進位的話,strtol裡面應該是16吧?
04/29 16:18, 3F

04/29 16:35, , 4F
謝謝大家,解決了。
04/29 16:35, 4F

04/29 16:35, , 5F
對欸,應該要打16才對,謝謝
04/29 16:35, 5F

04/29 16:51, , 6F
話說也可以打 sscanf(output2[i].c_str(),"%d",
04/29 16:51, 6F

04/29 16:52, , 7F
&dec[i]);
04/29 16:52, 7F
文章代碼(AID): #1Dkd647i (C_and_CPP)
文章代碼(AID): #1Dkd647i (C_and_CPP)