[問題] ifstream問題

看板EE_DSnP作者 (meanid)時間12年前 (2011/11/03 04:23), 編輯推噓4(401)
留言5則, 3人參與, 最新討論串1/1
再寫openDofile的時候 _dofile = new ifstream(dof.c_str); 然後要用_dofile呼叫她的member function的時候,像是 _dofile.eof() 或是 _dofile.close() 都會compile錯誤:request member for 'close' ...省略...'_dofile', which is non_class type "std::ifstream" 但是如果改成這樣呼叫:_dofile->eof(), 就可以了耶 為什麼會這樣啊?? 網路和書的參考資料都是_dofile.eof()呼叫的 _dofile是pointer?? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.245.82

11/03 04:25, , 1F
_dofile 的type是 ifstream * 所以要_dofile->close();
11/03 04:25, 1F

11/03 04:25, , 2F
可以去看cmdParser.cpp 的_dofile declaration
11/03 04:25, 2F
所以第一行應該寫成ifstream * _dofile = new ifstream(dof.c_str); 嗎? 還是說_dofile = new ifstream(dof.c_str);就已經讓_dofile 的type是ifstream *了? ※ 編輯: meanid 來自: 140.112.245.82 (11/03 04:34)

11/03 05:04, , 3F
你的理解是正確的. new回傳的是 address
11/03 05:04, 3F

11/03 06:40, , 4F
找一下_dofile 這個member data在哪裡被宣告成什麼樣子吧
11/03 06:40, 4F

11/03 08:13, , 5F
看一下 .h 檔裡 _dofile 的 type 是啥
11/03 08:13, 5F
文章代碼(AID): #1EiQRAD0 (EE_DSnP)