[問題] ofstream

看板C_and_CPP作者 (feketerigó)時間15年前 (2010/05/06 15:54), 編輯推噓2(201)
留言3則, 3人參與, 最新討論串1/3 (看更多)
我想請問一下 -------------------------------- char * foldername = "folder"; char * filename_1 = "1.txt"; char * filename_2 = "2.txt"; ofstream os1, os2; char * Filepath1 = new char; char * Filepath2 = new char; Filepath1 = filename_1; Filepath2 = filename_2; os1.open(filename_1); os2.open(filename_2); -------------------------------- 上面這段程式碼正常可以執行 但是加上下面標色部分卻會在os2.open的時候發生runtime error -------------------------------- char * foldername = "folder"; char * filename_1 = "1.txt"; char * filename_2 = "2.txt"; ofstream os1, os2; char * Filepath1 = new char; char * Filepath2 = new char; //期望 Filepath1="folder\1.txt" // Filepath2="folder\2.txt" strcpy(Filepath1, foldername); strcat(Filepath1, "\\"); strcat(Filepath1, filename_1); strcpy(Filepath2, foldername ); strcat(Filepath2, "\\"); strcat(Filepath2, filename_2); os1.open(Filepath1); os2.open(Filepath2); <-在執行這邊的時候終止 -------------------------------- 因為從上面的程式碼確定可以同時開多數個ofstream 下面的程式碼也可以用cout正確印出Filepath1 Filepath2的內容 所以不太懂錯誤究竟如何發生的 煩請指導 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 163.14.69.25

05/06 16:01, , 1F
新手十二戒第四項
05/06 16:01, 1F

05/06 17:34, , 2F
為啥不要用陣列來存阿? 真搞不懂
05/06 17:34, 2F

05/06 18:08, , 3F
也許是認為指標可完全同等於陣列吧~
05/06 18:08, 3F
文章代碼(AID): #1BudM-U1 (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1BudM-U1 (C_and_CPP)