From e3ae4cd3affc234e3127d5aa69c34f1c420b964d Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 5 Mar 2022 15:54:29 +0200 Subject: Added solutions from oop seminar 2 --- .../Solutions Sem. 02/exercise02.cpp | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Year 1/Object-oriented Programming/Solutions Sem. 02/exercise02.cpp (limited to 'Year 1/Object-oriented Programming/Solutions Sem. 02/exercise02.cpp') diff --git a/Year 1/Object-oriented Programming/Solutions Sem. 02/exercise02.cpp b/Year 1/Object-oriented Programming/Solutions Sem. 02/exercise02.cpp new file mode 100644 index 0000000..984a10b --- /dev/null +++ b/Year 1/Object-oriented Programming/Solutions Sem. 02/exercise02.cpp @@ -0,0 +1,32 @@ +#include // cin, cout +#include // ifstream, ofstream + +const int LINE_BUFFER_SIZE = 1024; +const int FILEPATH_SIZE = 4096; + +int main() { + char inName[FILEPATH_SIZE], outName[FILEPATH_SIZE]; + std::cin >> inName >> outName; + + std::ifstream inFile(inName); + if (!inFile.is_open()) { + std::cout << "Error: File could not be opened!" << std::endl; + return -1; + } + + std::ofstream outFile(outName); + if (!outFile.is_open()) { + std::cout << "Error: File could not be opened!" << std::endl; + return -1; + } + + char buffer[LINE_BUFFER_SIZE]; + while (!inFile.eof()) { + inFile.getline(buffer, LINE_BUFFER_SIZE); + outFile << buffer; + if (!inFile.eof()) outFile << std::endl; + } + + inFile.close(); + outFile.close(); +} -- cgit v1.3.1-23-gd82d