[問題] c++ 檔案輸出的一個問題
我是用Visual C的軟體,我想用"C++"的語法(非C),來做以下事情:
在in.txt檔案寫上"I like it",然候用c++讀取in.txt,並將in.txt的內容輸出到out.txt
。
程式碼如下:
ifstream ifile("c:\\ctest\\in.txt", ios::in);
ofstream oofile("c:\\ctest\\out.txt", ios::out);
if(ifile.is_open())
cout << "in已開啟" << endl;
else
cout << "in檔案開啟失敗" << endl;
if(oofile.is_open())
{
oofile << ifile << endl;
cout << "已將字串寫入檔案" << endl;
}
else
cout << "檔案開啟失敗" << endl;
ofile.close();
我in.txt已經可以被開啟,但是要怎麼將in.txt的內容輸出到out.txt,黃色這段
要怎麼寫呢? 我這樣寫出來的結果竟然是: 0012FE70 這是啥??
有點困惑了@@ 懇請版友指點!! 感謝!!
--
╭──╮ 全 q ˙ . 全 ╭════╮
║ 燈 電 世 . 潘 ◤◥◤◥ 陽 街 世 │此路不通│
║││ 了 界 ˙威 在 一 起 建 . 了 界 ╰═ ╤ ═╯
║ 停 都 ‧ 倫 ◣ ◢ 福 . 封 都 │
║ ﹕. ˙ ‧ ‧ │
███ ψsleeeve ███
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 36.224.117.208
※ 編輯: sleeeve 來自: 36.224.117.208 (08/23 01:31)
推
08/23 01:57, , 1F
08/23 01:57, 1F
→
08/23 01:57, , 2F
08/23 01:57, 2F
→
08/23 01:57, , 3F
08/23 01:57, 3F
→
08/23 01:58, , 4F
08/23 01:58, 4F
→
08/23 01:58, , 5F
08/23 01:58, 5F
推
08/23 05:54, , 6F
08/23 05:54, 6F
→
08/23 06:18, , 7F
08/23 06:18, 7F
→
08/23 06:19, , 8F
08/23 06:19, 8F
→
08/23 06:28, , 9F
08/23 06:28, 9F
→
08/23 06:39, , 10F
08/23 06:39, 10F
推
08/23 11:40, , 11F
08/23 11:40, 11F
→
08/23 11:40, , 12F
08/23 11:40, 12F
→
08/23 11:42, , 13F
08/23 11:42, 13F
恩恩,感謝大家!! 是想說ifile不是物件(用ifstream類別所建立的物件),還以為可以直
接傳給oofile...,原來還要透過新的變數。
※ 編輯: sleeeve 來自: 1.160.45.103 (08/23 12:48)
→
08/24 14:49, , 14F
08/24 14:49, 14F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章