close secretMessage

This commit is contained in:
Tyler Beckman 2024-09-25 14:08:33 -06:00
parent d3173832fd
commit 6920e0c6f9
Signed by: Ty
GPG key ID: 2813440C772555A4

View file

@ -10,31 +10,32 @@
#include <iostream>
int main(void) {
std::ifstream secretMessage("secretMessage.txt");
if (secretMessage.fail()) {
std::cerr << "Error opening secretMessage.txt file" << std::endl;
return -1;
}
std::ifstream secretMessage("secretMessage.txt");
if (secretMessage.fail()) {
std::cerr << "Error opening secretMessage.txt file" << std::endl;
return -1;
}
std::ofstream decipheredMessage("decipheredMessage.txt");
if (decipheredMessage.fail()) {
std::cerr << "Error opening decipheredMessage.txt" << std::endl;
return -1;
}
std::ofstream decipheredMessage("decipheredMessage.txt");
if (decipheredMessage.fail()) {
std::cerr << "Error opening decipheredMessage.txt" << std::endl;
return -1;
}
char currentChar;
while (secretMessage.get(currentChar)) {
switch (currentChar) {
case '\n':
decipheredMessage << std::endl;
break;
case '~':
decipheredMessage << ' ';
break;
default:
decipheredMessage << (char)(currentChar + 1);
}
}
char currentChar;
while (secretMessage.get(currentChar)) {
switch (currentChar) {
case '\n':
decipheredMessage << std::endl;
break;
case '~':
decipheredMessage << ' ';
break;
default:
decipheredMessage << (char)(currentChar + 1);
}
}
decipheredMessage.close();
secretMessage.close();
decipheredMessage.close();
}