How to APPEND column in a text file

I have a txt file (1.txt) with one column. I want to add some data from other file (2.txt) to the second column of 1.txt. I am using ios::app, but the new data from the 2.txt is being added after the previous data in 1.txt, not in a new column.

how to add the data in a new column in 1.txt??
Simple answer, you cannot. A text file, any file to my knowledge, goes horizontally, until a newline character is encountered, then moves to a new line.

Nontheless, you can write a function that copies the content of 1.txt (a column of data) and 2.txt into two buffers, buff1, and buff2.

Now, what you can do is this:
1
2
3
4
5
6
int i;
for (i = 0; i < size; i++)
{
    outData << buff1[i] << "   " << buff2[i] << endl;
}


where outData is an ofstream.
Topic archived. No new replies allowed.