[問題] BCB讀TXT檔問題

看板C_and_CPP (C/C++)作者 (sevenone)時間15年前 (2011/05/22 14:52), 編輯推噓1(102)
留言3則, 1人參與, 最新討論串1/1
開發平台(Platform): BCB 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 我使用BCB讀入TXT檔存入Buffer 檔案裡面包含N*1矩陣的Float 範例檔矩陣530行的Float 但是讀出Size為9xxx 且數值跟TXT檔裡完全不同 void __fastcall TForm1::Button1Click(TObject *Sender) { float apo; if(!OpenDialog1->Execute()) return; TMemoryStream *Bytestream = new TMemoryStream(); Bytestream->LoadFromFile(OpenDialog1->FileName); int t_filesize = Bytestream->Size; for(int index=0;index<t_filesize;index++) Bytestream->Read(&apo,index); delete Bytestream; } t_filesize 數值是錯的 Bytestream 數值也是錯的 請問是哪裡出了問題?? TXT檔內容如下: -1.0000000e+000 -1.0000000e+000 -1.0000000e+000 -1.0000000e+000 -1.0000000e+000 -1.0000000e+000 .... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.41.121.222

05/22 14:58, , 1F
你的.txt是文字內容吧?? 這樣read是直接當binary讀啊.
05/22 14:58, 1F

05/22 15:00, , 2F
檔案大小(bytes)不見得等於資料筆數; ASCII文字檔內容也
05/22 15:00, 2F

05/22 15:00, , 3F
不是這樣直接用binary read的方式來解讀的.
05/22 15:00, 3F
文章代碼(AID): #1DsBAjfr (C_and_CPP)
文章代碼(AID): #1DsBAjfr (C_and_CPP)