[問題] CLR使用Net函式庫讀檔問題
開發平台(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
04/23 20:31, 4F
※ 編輯: tanker 來自: 112.104.74.31 (04/23 22:16)
※ 編輯: tanker 來自: 112.104.74.31 (04/23 22:33)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章