diff options
1 files changed, 32 insertions, 0 deletions
| -rw-r--r-- | Year 1/Object-oriented Programming/Solutions Sem. 02/exercise02.cpp | 32 |
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 <iostream> // cin, cout +#include <fstream> // 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(); +} |
