Re: [問題] C++程式碼

看板C_and_CPP (C/C++)作者 (某數要尋找暑假工作機會)時間15年前 (2010/07/24 21:51), 編輯推噓4(401)
留言5則, 5人參與, 最新討論串1/1
我們先到這個網站來http://www.cplusplus.com/reference/ ※ 引述《zx33571163 (mm)》之銘言: : #include <iostream> : #include <fstream> include fstream 所以要找fstream 網站往下拉到最底找到fstream點進去 就是此頁 http://www.cplusplus.com/reference/iostream/fstream/ : using namespace std; : int main() : { : ifstream fin("1.txt"); 這邊用的可以猜想他是constructor 到這邊發現有問題 我們要ifstream 不是fstream 所以回到第一個連結點ifstream 然後找他的constructor example的程式碼第8行是這樣 ifstream ifs ( "test.txt" , ifstream::in ); 所以我們找到了 : cout << "輸入"<<endl; : if(!fin){ cout << "讀檔失敗" << endl; } // 檢查讀檔成功與否 fin是ifstream物件 接下來你自己找吧@@ 我這個英文被當光光的傢伙都會找了= =a 不過我猜想if(!fin)是因為如果開啟1.txt失敗會傳回NULL 所以讀檔失敗 : char s[2]; : while (fin.good()) : cout << (char) fin.get(); 提示你一下這是形態轉換 : fin.close(); // 關閉檔案 : system("pause"); : return 0; : } : ________________________________________________________________________ : while (fin.good()) : ^^^^^^^^^^^^^ : cout << (char) fin.get(); : ^^^^^^^^^^^^^^^^^^ : 這2行的意思跟語法可以幫我解釋一下嗎 : 看不太懂 : 謝謝 順便幫你抓過來啦!! Member functions inherited from ios good Check if the state of the stream is good for i/o operations. (public member function) Members inherited from istream get Get unformatted data from stream (public member function) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.240.38.21

07/24 21:59, , 1F
謝謝 新手上路不要太苛求啦
07/24 21:59, 1F

07/24 22:00, , 2F
學會利用網路資源很重要@@"
07/24 22:00, 2F

07/25 16:57, , 3F
你問的都是隨便查就查的到的耶,這不算苛求吧...
07/25 16:57, 3F

07/26 12:37, , 4F
語法什麼的不會都無所謂,「自己查資料」一定要會
07/26 12:37, 4F

08/01 20:09, , 5F
推不只給你魚吃還教你釣魚
08/01 20:09, 5F
文章代碼(AID): #1CIk_z-g (C_and_CPP)
文章代碼(AID): #1CIk_z-g (C_and_CPP)