How to add 4 file make one file with 4 column

Hi everyone,
I have 4 file.txt individually, I want to add to one file with 4 columns.
I can add file, but, no making to 4 columns.
How can fix it?
Thank you too much.

This code is:............

int docfile(int);
//--------------------------------------OPEN FILE AND READ IT------------------------------------------------

int docfile(int n)
{
int i;
int k,l;
int a[1][N];
char f[100];
char r[100];

cout<<"So luong file can nhap: ";
cin>>n;

for (i=0; i<n; i++){
cout<<"Nhap ten file"<<endl;
cin>>f;
ifstream openfile(f,ios::in);

cout<<"Nhap file muon luu: "<<endl;
cin>>r;
ofstream outfile(r,ios::out);

if (openfile.is_open()){
for (k=0;k<1;k++) {
for (l=0;l<N;l++){
openfile>>a[k][l];
if (l<=2) a[k][l]=0;
cout<<a[k][l]<<endl;
//a[j][i]=a[j][i];
outfile<<openfile.rdbuf()<<endl;

}}

}

openfile.close();
outfile.close();
// return 0;
}
}
Last edited on
A program like that does already exist: http://linux.die.net/man/1/paste

Conceptually it is really easy:
1. Take one line from each file. You get strings.
2. Concatenate strings together and write the result to output.
3. Repeat from 1.
For example:
File 1:
1
2
3
File 2
7
8
9
File 3
12
13
14
File 4
17
18
19
Make one file:
1 7 12 17
2 8 13 18
3 9 14 19

I don't know the algorithm for doing. Can you explain clearly?
Thank u too much!
Topic archived. No new replies allowed.