새로새록
[c++]4. 두개의 텍스트파일 합치기 본문
4. 아래와 같은 두개의 다른 텍스트파일을 하나의 텍스트 파일로 합치는 프로그램을 작성하라. (단,
줄바꿈도 텍스트 파일 형식에 포함된다)
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
char ch;
ofstream ofs;
ofs.open("output.txt");
ifstream ifs;
ifs.open("input1.txt");
while (ifs.get(ch))
ofs.put(ch);
ifs.close();
ifs.open("input2.txt");
ofs.put('\n');
ofs.put('\n');
while (ifs.get(ch))
ofs.put(ch);
ifs.close();
ofs.close();
return 0;
}
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
ofstream res("integrated.txt");
ifstream s1("input1.txt");
ifstream s2("input2.txt");
string line;
while (getline(s1, line)) {
res << line << endl;
}
s1.close();
res << endl;
while (getline(s2, line)) {
res << line << endl;
}
s2.close();
res.close();
return 0;
}
'소프트웨어융합 > 경희대 c++ 과제' 카테고리의 다른 글
[c++] 5. vector 역순으로 만들기 (0) | 2020.07.15 |
---|---|
[c++]4. 최대 길이를 정한 텍스트파일 (0) | 2020.07.15 |
[c++]4. 10*10 행렬 (0) | 2020.07.14 |
[c++]4. 검색엔진 - 키워드 포함 단어 (0) | 2020.07.14 |
[c++]입력된 숫자들 중 가장 큰 값 max (0) | 2020.07.13 |