#include#include int main() { std::ifstream inputFile("input.txt"); std::ofstream outputFile("output.txt"); if (inputFile.is_open() && outputFile.is_open()) { std::string line; while (std::getline(inputFile, line)) { outputFile << line << "\n"; } inputFile.close(); outputFile.close(); } else { std::cout << "Failed to open file!" << std::endl; } return 0; }
#includeBoth examples use the fstream library, which is part of the C++ Standard Library.#include int main() { std::ofstream outputFile("output.txt"); if (outputFile.is_open()) { std::string line; while (std::getline(std::cin, line)) { outputFile << line << "\n"; } outputFile.close(); } else { std::cout << "Failed to open file!" << std::endl; } return 0; }