看板 Programming 關於我們 聯絡資訊
※ [本文轉錄自 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
sky008888:ios_base::binary218.174.199.150 03/20 00:54
sky008888:還有 namespace, else {....}, 這些改一218.174.199.150 03/20 01:02
sky008888:下就好了 (我改完回應是 file open su..218.174.199.150 03/20 01:03
謝謝您的回覆,但是我改了之後還是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)
Uihc:對不起.我知道原因了..我檔案放錯目錄了 >"< 61.31.149.50 03/20 01:13
Uihc:很謝謝您!^^ 61.31.149.50 03/20 01:13