이 코드를 작성하는 데 문제가 있습니다. 컴파일을 작성했습니다. 이 코드는 두 개의 텍스트 파일을 통해 읽은 다음이 두 파일 내에 줄을 출력합니다. 그런 다음 두 파일을 넣고 결합 할 수 있지만 첫 번째 줄에는 file1 텍스트, 그 다음 줄에는 file2 텍스트가 있어야합니다. 모든두 개의 텍스트 파일을 읽은 다음 결합하여
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
using namespace std;
int main()
{
std::ifstream file1("file1.txt");
std::ifstream file2("file2.txt");
//std::ofstream combinedfile("combinedfile.txt");
//combinedfile << file1.rdbuf() << file2.rdbuf();
char filename[400];
string line;
string line2;
cout << "Enter name of file 1(including .txt): ";
cin >> filename;
file1.open(filename);
cout << "Enter name of file 2 (including .txt): ";
cin >> filename;
file2.open(filename);
if (file1.is_open())
{
while (file1.good())
{
getline (filename,line);
cout << line << endl;
}
file1.close();
}
else cout << "Unable to open file";
return 0;
}
if (file2.is_open())
{
while (file2.good())
{
getline (filename,line);
cout << line << endl;
}
file2.close();
}
else cout << "Unable to open file";
return 0;}
컴파일러는 무엇을 말합니까? – HAL