[問題] ofstream

看板C_and_CPP作者 (feketerigó)時間15年前 (2010/06/07 20:32), 編輯推噓3(307)
留言10則, 3人參與, 最新討論串2/3 (看更多)
完整程式碼如下: -- #include<iostream> #include<fstream> using namespace std; int main(int argc, char ** argv){ ifstream ifs; ofstream ofs; ofs.open("out.txt"); if (argc > 1){ ifs.open(argv[1]); } else{ ifs.open("ifs.txt"); } if (ofs){ cout << "success" << endl; } else{ cout << "failed" << endl; } ofs << "123456"; ofs.close(); system("pause"); return 0; } -- 如果我直接執行這隻程式 可以正確產生出out.txt 如果把檔案拖進去執行讓 ifs.open(argv[1]) 雖然會印出success 但是卻不產生out.txt檔案 請問這個問題點是出在哪邊呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 163.14.5.121 ※ 編輯: applerev 來自: 163.14.5.121 (06/07 20:34)

06/07 21:07, , 1F
我測試的結果是有的 :P
06/07 21:07, 1F

06/07 21:17, , 2F
我用了兩台電腦都沒有@@ 我是直接拖一個檔案到exe上
06/07 21:17, 2F

06/07 21:25, , 3F
你的argv[1]是顯示什麼?
06/07 21:25, 3F

06/07 22:09, , 4F
拖進去的檔案名阿 可是輸出不是和那個無關嗎?
06/07 22:09, 4F

06/07 22:17, , 5F
試試直接在 command-line 下執行?
06/07 22:17, 5F

06/07 23:43, , 6F
真糟...還是沒有= =
06/07 23:43, 6F

06/08 01:21, , 7F
我測試也是可以
06/08 01:21, 7F
改成完整程式碼好了...orz 目前還是一樣沒進展... ※ 編輯: applerev 來自: 114.44.170.28 (06/08 02:51)

06/08 02:56, , 8F
compiler跟os是?
06/08 02:56, 8F

06/08 17:15, , 9F
XP SP3 CODEBLOCK8.02
06/08 17:15, 9F

06/08 18:42, , 10F
compiler是MinGW
06/08 18:42, 10F
文章代碼(AID): #1C3EROGs (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1C3EROGs (C_and_CPP)