[問題] CLR使用Net函式庫讀檔問題

看板C_and_CPP (C/C++)作者 (阿湯貓)時間15年前 (2011/04/23 16:13), 編輯推噓0(004)
留言4則, 2人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) VC++2008 問題(Question): 使用CLR的目的是為了可給Winform的函式,讀文字檔並將其存成陣列 錯誤結果(Wrong Output): 陣列顯示每行皆為0 程式碼(Code):(請善用置底文網頁, 記得排版) int main(array<System::String ^> ^args) { Console::WriteLine(L"Hello World"); int ^i,^j=0; FileStream ^fs= gcnew FileStream("file.txt" ,FileMode::Open); int nBytes=Convert::ToInt32(fs->Length); array <Byte> ^ByteArray = gcnew array <Byte> (nBytes); fs->Position =0; String ^tmp = " "; for (int i=0 ;i<ByteArray->Length;i++) tmp= tmp+ (char)fs->ReadByte(); for (int i=0 ;i<ByteArray->Length;i++) Console::WriteLine("{0}", ByteArray[i]); return 0; } 存成ByteArray後,使用WriteLine輸出這裡請問出了什麼問題呢? 請問讀取file.txt的部份 照理說有逐行讀取了,可是卻沒存入陣列裡,不知道是哪裡錯了 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 112.104.152.134

04/23 20:27, , 1F
請詳述問題以及錯誤訊息, 同樣的問題請用編輯內文,
04/23 20:27, 1F

04/23 20:28, , 2F
勿重複發表多篇文章
04/23 20:28, 2F

04/23 20:30, , 3F
嗯那這篇請幫我刪掉,謝謝
04/23 20:30, 3F

04/23 20:31, , 4F
ByteArray 沒值的原因是因為你沒有讀東西存進去
04/23 20:31, 4F
※ 編輯: tanker 來自: 112.104.74.31 (04/23 22:16) ※ 編輯: tanker 來自: 112.104.74.31 (04/23 22:33)
文章代碼(AID): #1Dieexx0 (C_and_CPP)
文章代碼(AID): #1Dieexx0 (C_and_CPP)