From ca5ba538077d62d0fc7331d7838a6660062edbb8 Mon Sep 17 00:00:00 2001 From: "James2.Hoole-Jackson@live.uwe.ac.uk" <james2.hoole-jackson@live.uwe.ac.uk> Date: Wed, 30 Apr 2025 13:20:28 +0000 Subject: [PATCH] attemp at stopping overwritten files --- EncryptDecrypt.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/EncryptDecrypt.cpp b/EncryptDecrypt.cpp index f3227ae..6fc5f23 100644 --- a/EncryptDecrypt.cpp +++ b/EncryptDecrypt.cpp @@ -57,7 +57,12 @@ std::string readFile(const std::string& fileName) { return content; } -void writeFile(const std::string& fileName, const std::string& content) { +void writeFile(const std::string& fileName, const std::string& content, const std::string& inputFileName) { + if (fileName == inputFileName) { + std::cerr << "Error: Cannot overwrite the original input file: " << fileName << "\n"; + return; + } + std::ofstream file(fileName); if (!file.is_open()) { std::cerr << "Error: Unable to open file for writing: " << fileName << "\n"; @@ -66,3 +71,13 @@ void writeFile(const std::string& fileName, const std::string& content) { file << content; file.close(); } + + //void writeFile(const std::string& fileName, const std::string& content) { + //std::ofstream file(fileName); + //if (!file.is_open()) { + //std::cerr << "Error: Unable to open file for writing: " << fileName << "\n"; + //return; + //} + //file << content; + //file.close(); +//} -- GitLab