[問題] ofstream
我想請問一下
--------------------------------
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
討論串 (同標題文章)