[問題] 讀檔的問題

看板Programming作者 (我 有我的倔強...)時間18年前 (2007/03/20 00:52), 編輯推噓2(203)
留言5則, 2人參與, 最新討論串1/2 (看更多)
※ [本文轉錄自 C_and_CPP 看板] 作者: Uihc (我 有我的倔強...) 看板: C_and_CPP 標題: [問題] 讀檔的問題 時間: Mon Mar 19 19:05:04 2007 請教各位,我有一個檔案用ultraedit或visual studio都可以打開來 檔案在下面連結 http://140.112.64.235/test 內容看起來是就像 45 00 00 00 1E 00 00 00 FF 00 00 00 2F 00 00 00 : : 但我寫了一小段程式想去讀它時 都回應無法打開檔案 char ch[50]; ifstream is("test",ios::binary); if(is) { cout << "File Open Success!" << endl; is.read(ch,sizeof(ch)); } else cout << "ERROR: Cannot open file ." << endl; 想請版上的前輩幫忙看看這個檔案,我應該怎麼讀檔才是對的呢? 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.64.235 ※ 編輯: Uihc 來自: 140.112.64.235 (03/19 19:05) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.31.149.50

03/20 00:54, , 1F
ios_base::binary
03/20 00:54, 1F

03/20 01:02, , 2F
還有 namespace, else {....}, 這些改一
03/20 01:02, 2F

03/20 01:03, , 3F
下就好了 (我改完回應是 file open su..
03/20 01:03, 3F
謝謝您的回覆,但是我改了之後還是error >"< 程式碼在下面.. 我是用vs2005~ #include "stdafx.h" #include <fstream>//for ifstream #include <iostream>//for cout using namespace std; int _tmain(int argc, _TCHAR* argv[]) { char ch[50]; ifstream is("test",ios_base::binary); if(is) { cout << "File Open Success!" << endl; is.read(ch,sizeof(ch)); } else cout << "ERROR: Cannot open file ." << endl; } ※ 編輯: Uihc 來自: 61.31.149.50 (03/20 01:11)

03/20 01:13, , 4F
對不起.我知道原因了..我檔案放錯目錄了 >"<
03/20 01:13, 4F

03/20 01:13, , 5F
很謝謝您!^^
03/20 01:13, 5F
文章代碼(AID): #15_h-vAX (Programming)
討論串 (同標題文章)
文章代碼(AID): #15_h-vAX (Programming)