Combining 2 single line text files with a multiline text file

Hi, I am new to C++ and trying to find a way to merge three text files together to create an output text with them merged. I have been doing it through excel and just tired of having to combine them like that and looking to make it so i can just use an exe with the sites i load into 2.txt but my problem is that if i load a list into 2.txt with say 10 lines i wont get the other 2 files added to each line of the other 9 lines. I need the one line from 1.txt and 3.txt to apply to every line in 2.txt whether i have 5 lines or 600 lines in 2.txt. any help to get this to happen would great! here is the code im using. and an example of what i need it to do
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <fstream>
#include <ostream>

using namespace std;

int main()
{
   ifstream in1("1.txt", ios::in | ios::binary);
   if(!in1)
   {
      cout << "Cannot open input file 1.\n";
      return 1;
   }
   ifstream in2("2.txt", ios::in | ios::binary);
   if(!in2)
   {
      cout << "Cannot open input file 2.\n";
      return 1;
   }
   ifstream in3("3.txt", ios::in | ios::binary);
   if(!in3)
   {
      cout << "Cannot open input file 3.\n";
      return 1;
   }
   ofstream out("outtest.txt", ios::out | ios::binary);

   if(!out)
   {
      cout << "can't open output file ";
      return 1;
   }

   out << in1.rdbuf();
   out << in2.rdbuf();
   out << in3.rdbuf();

   return 0;
   }

which is great but i need to make sure that if i add more lines to text 2

1.txt includes:
:@

2.txt includes: but will have different amounts of lines
http://www.test.com/
http://www.test1.com/
http://www.test2.com/
http://www.test3.com/

3.txt includes:
:@

I need the output to put it all together like this:

:@http://www.test.com/ :@
:@http://www.test1.com/ :@
:@http://www.test2.com/ :@

and so on..
Last edited on
Process the files per line.
1
2
while( getline(input, line) )
   output << prefix + line + suffix << '\n';
where would i need to put that?
You are just concatenating the files, instead of that process the big one (2.txt) line per line.
i dont understand what you mean? sorry like i said im new to c++
Topic archived. No new replies allowed.