Yes, it can be done. Open each file for reading and if they both opened successfully you:
Read the contents of each file into two strings (std::string really recommended), one string for each file, one line at a time, reading the files as the condition statement for a while loop makes it easy to stop the loop when the end of either file is read.
Within the while loop block:
1. For the output file name you create a string with the read emoji name and concatenate it with ".txt"
2. Open for writing a file using the created file name.
3. Write the read code string to the file.
4. Close the file.
5. The loop repeats until either file has been read to EOF.
If the last code compiles OK, then you're using a C++98 compiler - which is vastly out of date. I'd really suggest updating to a current C++ compiler (C++17/20).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <fstream>
#include <iostream>
#include <string>
int main()
{
std::ifstream if1("emoji.txt");
std::ifstream if2("code.txt");
if (!if1.is_open() || !if2.is_open())
return (std::cout << "Cannot open files\n"), 1;
for (std::string f1, f2; std::getline(if1, f1) && std::getline(if2, f2); ) {
std::ofstream of((f1 + ".txt").c_str());
of << f1 << '\n' << f2 << '\n';
}
}