I've a multiline file, every line a string.
Example of code.txt
:
AAAAA
BB33A
C544W
I have to put some code contained in another file before every string. I'm using this:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
//the file to include before every string
ifstream one("1.txt");
//final output file
ofstream final;
final.open ("final.txt", ofstream::app);
//string file
string line;
ifstream file("code.txt");
while (getline(file,line))
{
final<<one.rdbuf();
final<<line;
}
}
Now, this doesn't work, it works only for the first line of code.txt
. What is wrong?