[問題] Streams and File I/O
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Dec C++ 4.9.9.2
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
餵入的資料(Input):
預期的正確結果(Expected Output):
我是看原文書
原文書說會跑出一個叫numstory.txt的檔案,而且裡面會有跟story.txt一樣的資料
錯誤結果(Wrong Output):
找不到numstory.txt
自己建一個numstory.txt卻沒改變
不過後來把code裡的.TXT拿掉並且把純文字檔的檔名也去掉.TXT
就可以了
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <fstream>
#include <iostream>
#include <cstdlib>
using std::ifstream;
using std::ofstream;
using std::cout;
int main()
{
ifstream fin;
ofstream fout;
fin.open("story.txt");
if(fin.fail())
{
cout<<"Input file opening failed.\n";
exit(1);
}
fout.open("numstory.txt");
if(fout.fail())
{
cout<<"Output file opening failed.\n";
exit(1);
}
char next;
int n=1;
fin.get(next);
fout<<n<<" ";
while(!fin.eof())
{
fout<<next;
if(next=='\n')
{
n++;
fout<<n<<' ';
}
fin.get(next);
}
fin.close();
fout.close();
return 0;
}
補充說明(Supplement):
原文書Absolute C++ 4版 範例12.4
麻煩指點迷津
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 58.114.105.94
→
07/04 14:12, , 1F
07/04 14:12, 1F
不懂 什麼意思?
※ 編輯: fkms 來自: 58.114.105.94 (07/04 14:22)
※ 編輯: fkms 來自: 58.114.105.94 (07/04 14:22)
※ 編輯: fkms 來自: 58.114.105.94 (07/04 14:49)
※ 編輯: fkms 來自: 58.114.105.94 (07/04 14:49)
→
07/04 14:55, , 2F
07/04 14:55, 2F
→
07/04 14:55, , 3F
07/04 14:55, 3F
推
07/04 15:07, , 4F
07/04 15:07, 4F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章