[問題] I/O的複製
各位前輩好
因為最近在看I/O
所以小弟自己練習寫了一個很簡單的小程式
題目:
在同一個目錄下有兩個檔案 我把想把其中一各檔案串接在另一各檔案後
但不知道為什麼串接都會有文字被砍..
例如:
我在out的檔案有一個 I am a boy , and
在in檔案裡面有一個 you are a girl!
但是執行程式後卻變成 I am a boy , andgirl!
我不知道哪裡的觀念有出現問題..可以請前輩指點一下嗎?
#include<fstream>
#include<iostream>
#include<cstdlib>
#include<string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::ifstream;
using std::ofstream;
int main( int argc , char *argv[] )
{
ifstream infile("in.txt");
ofstream outfile("out.txt" , ofstream::out | ofstream::app )
string s;
while( ! infile.eof() )
{
infile >> s;
}
infile.close();
outfile << s << endl;
outfile.close();
return EXIT_SUCCESS;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 61.20.158.26
推
12/17 11:45, , 1F
12/17 11:45, 1F
→
12/17 11:47, , 2F
12/17 11:47, 2F
→
12/17 11:48, , 3F
12/17 11:48, 3F
→
12/17 11:48, , 4F
12/17 11:48, 4F
推
12/17 11:51, , 5F
12/17 11:51, 5F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章