#include <iostream>
#include <fstream>
int main() {
// Step 1: Declare variables
std::ifstream inputFile;
std::ofstream outputFile;
// Step 2: Open input file in binary mode
inputFile.open("input.txt", std::ios::binary);
// Step 3: Check if the input file is successfully opened
if (!inputFile.is_open()) {
std::cerr << "Error opening input file." << std::endl;
return 1; // Exit with an error code
}
// Step 4: Open output file in binary mode with std::ios::app flag
outputFile.open("output.txt", std::ios::binary | std::ios::app);
// Step 5: Check if the output file is successfully opened
if (!outputFile.is_open()) {
std::cerr << "Error opening output file." << std::endl;
return 1; // Exit with an error code
}
// Step 6: Read data from the input file and write to the output file
char buffer[1024];
while (inputFile.read(buffer, sizeof(buffer))) {
outputFile.write(buffer, inputFile.gcount());
}
// Step 7: Close the file streams
inputFile.close();
outputFile.close();
return 0; // Exit successfully
}