看板 C_and_CPP 關於我們 聯絡資訊
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) VC++ 問題(Question): 想進行大筆資料檔案處理 要利用CSV檔的特性 逐行讀取 取出可用於 陣列的數值 預期的正確結果(Expected Output): 預期是 每讀一行開一個檔案 檔案編號從0.txt開始 逐一增加 錯誤結果(Wrong Output): 結果只開一個檔案.. 程式碼(Code):(請善用置底文網頁, 記得排版) int main(){ ifstream out; ofstream in; int cou=0; char buffer[9999]; char format[]=".txt"; char c[4]; out.open("Book1.csv"); if(!out) { cout<<"file is failed"<<endl; }else { while(!out.eof()) { out.getline(buffer,sizeof(buffer)); itoa(cou, c, 10); strcat(c, format); in.open(format, ios::out); if(!in) cout << "file is failed " << endl; in<<buffer; cou++; in.close(); cout<<buffer<<endl; cout<<c; } } system("pause"); return 0; } 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.238.64.122 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1458840834.A.97B.html
Schottky: 你把打算要 open 的檔名 print 出來就知道問題在哪了 03/25 01:44
謝謝又耍笨了 ※ 編輯: kevinqazwsx (36.238.64.122), 03/25/2016 01:51:34
Schottky: 我也常常這樣 XD 03/25 02:23
Schottky: 請教一個問題,在本板常看到像你一樣,貼出來的程式碼 03/25 02:24
Schottky: 縮排沒對齊亂掉的,是原本就沒縮好還是剪貼時才亂掉的? 03/25 02:25
Schottky: 我是用 indent 指令重排一次才看懂階層架構的 03/25 02:27
petercoin: 我猜是用tab寫code但是tab沒有被space取代? 03/25 11:05
james732: 話說都用C++了,考慮用string代替char[]吧 03/25 12:27
tinlans: 他大概想省下用 .c_str () 丟 fstream 的時間 XD 03/28 12:09
BlazarArc: C++11 有 string overload 啊 03/28 12:52
Schottky: 這基本上還是在寫 C,只不過誤用了 iostream 而已 03/28 14:20