[問題] winform 讀取字串特定數字的問題

看板C_and_CPP (C/C++)作者 (阿湯貓)時間15年前 (2011/04/22 22:18), 編輯推噓0(005)
留言5則, 2人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) VC++ Windows Form 最近好不容易搞懂普通C++的讀取特定數字的問題 但是又需要改成Winform來寫,小弟已經有買VC++ 2008樂活學來研究了 可是還是不太懂這種視窗程式的寫法 程式碼(Code):(請善用置底文網頁, 記得排版) 目前這是只讀取一行字串的寫法,需求是讀取每行字串裡的兩個數字,求出最常出現的 那個數字顯示在Textbox上 static array<String^> ^words=gcnew array <String^>(1000); private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { String ^file="file.txt"; FileStream^ fs =gcnew FileStream(file ,FileMode::Open); StreamReader^ sr =gcnew StreamReader(fs); String ^tmp1=" "; while (sr->Peek() != -1) { String ^currentRow = sr->ReadLine(); tmp1 += currentRow +="\r\n"; } sr->Close(); fs->Close(); } 另外這是原本C++的程式碼 int main(int argc, char *argv[]) { int i=0,t=0; fstream fin("file.txt",ios::in); string tmp=""; if(fin.fail()) cout<<"Error\n"; while(!fin.eof()) { for (i=0;i<25;i++) { while(fin>>tmp) //將不想要的字串讀入 { if(tmp == "Temp:")//如果是"temp,則準備讀入數字 { fin>>temper[i]; break; } } } } } 補充說明(Supplement): 文件檔裡的資料大概是這樣的,也就是需要將30,29,21存入陣列應用 2008/05/29 humidity: 24 temperature : 30 Reading... 2008/05/30 humidity: 48 temperature : 29 Reading... 2008/06/01 humidity: 35 temperature : 21 Reading... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 112.104.75.237 ※ 編輯: tanker 來自: 112.104.75.237 (04/22 22:21)

04/22 22:24, , 1F
跳太快了, 先開一個「CLR主控台應用程式」來寫, 使用
04/22 22:24, 1F

04/22 22:25, , 2F
.NET 庫來做, 測試開檔功能無誤再將你想作的事情分成
04/22 22:25, 2F

04/22 22:26, , 3F
函式, 按按鈕只是變成呼叫 obj.function(...) 而已
04/22 22:26, 3F

04/23 13:52, , 4F
那想請問Read(buffer,m,n)可以使用嗎?
04/23 13:52, 4F

04/23 14:44, , 5F
.Net庫是指一樣不能包含iostream這些用法嗎?
04/23 14:44, 5F
文章代碼(AID): #1DiOuenU (C_and_CPP)
文章代碼(AID): #1DiOuenU (C_and_CPP)