#include <iostream>
#include <fstream>
#include <string>
#include <stdexcept>
void readFileAndWriteToFile() {
std::ifstream inputFile("input.txt");
std::ofstream outputFile("output.txt");
if (!inputFile.is_open()) {
throw std::runtime_error("Unable to open input file.");
}
if (!outputFile.is_open()) {
throw std::runtime_error("Unable to create/open output file.");
}
std::string line;
while (std::getline(inputFile, line)) {
outputFile << line << std::endl;
}
inputFile.close();
outputFile.close();
}
int main() {
try {
readFileAndWriteToFile();
std::cout << "Data copied from input.txt to output.txt successfully." << std::endl;
} catch (std::exception& ex) {
std::cout << "Exception caught: " << ex.what() << std::endl;
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: