Re: [問題] C++程式碼
我們先到這個網站來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
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章