我有多个文本文件,我从一个文本文件中分离出来,现在我想将它们与,分离的表单合并,但是列与序列合并。
data1.txt
A man in the park
A man in the ground
A man is runningdata2.txt
Yes1
No1
Why not1data3.txt
Yes2
No2
Why not2data4.txt
Yes3
No3
Why not3data5.txt
Yes4
No4
Why not4如何使用csv将这些数据文件合并为逗号分隔值( c++ )文件
1,A man in the park,Yes1,Yes2,Yes3,Yes4
2,A man in the ground,No1,No2,No3,No4
3,A man is running,Why not1,Why not2,Why not3 , Why not4我看到了相关关于它的问题,但它与c++无关
发布于 2014-07-07 15:49:04
您试过一次打开所有文件并为每个输入文件使用一个字符串吗?
unsigned int line_number = 1;
ifstream file1("data1.txt");
ifstream file1("data2.txt");
ifstream file1("data3.txt");
ifstream file1("data4.txt");
ifstream file1("data5.txt");
ofstream out("output.txt");
std::string input1;
std::string input2;
std::string input3;
std::string input4;
std::string input5;
getline(file1, input1);
getline(file2, input2);
getline(file3, input3);
getline(file4, input4);
getline(file5, input5);
out << line_number
<< ", " << input1
<< ", " << input2
<< ", " << input3
<< ", " << input4
<< ", " << input5
<< "\n";以上代码是基本原则。读取器和OP需要将代码放入循环并添加错误检查。这是以“批处理”模式构造的,其中许多相关操作被聚集在一起。
是的,上面的代码可以简化,但只是为了说明。
https://stackoverflow.com/questions/24614349
复制相似问题