My issue
not solving
My code
#include <iostream>
#include <fstream>
void processFile() {
std::string inputfilename = "/home/codechef/input.txt";
std::ifstream inputfile(inputfilename);
if (!inputfile.is_open()) {
std::cerr << "Error opening input file\n";
return;
}
std::string outputfilename = "/home/codechef/output.txt";
std::ofstream outputfile(outputfilename);
if (!outputfile.is_open()) {
std::cerr << "Error opening output file\n";
inputfile.close();
return;
}
int number;
// Read and write the numbers from the file
while (inputfile >> number) {
outputfile << number << '\n';
}
inputfile.close();
outputfile.close();
// Display the contents of the output file
inputfile.open(outputfilename);
if (!inputfile.is_open()) {
std::cerr << "Error reopening output file\n";
return;
}
std::cout << "Contents of output.txt:\n";
while (inputfile >> number) {
std::cout << number << '\n';
}
inputfile.close();
}
int main() {
processFile();
return 0;
}
Learning course: Learn Programming and Problem Solving using C++
Problem Link: https://www.codechef.com/learn/course/sit-cpp-fall/SITFALL52/problems/CPPFALL340