【发布时间】:2015-10-30 03:39:22
【问题描述】:
我正在尝试将 2 个文件复制到 1 个文件中,例如 标识 1 。名称 1 。 身份证2。名称2。 但我做不到...我应该如何从每个文件中复制每一行。
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream file1("ID.txt");
ifstream file2("fullname.txt");
ofstream file4("test.txt");
string x,y;
while (file1 >> x )
{
file4 << x <<" . ";
while (file2 >> y)
{
file4 << y <<" . "<< endl;
}
}
}
【问题讨论】:
-
也许可以看看std::getline。
-
或者您可以使用已经完成此操作的工具。
paste ID.txt fullname.txt > test.txt