#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
class Paragraph {
public:
void setCode();
void getCode();
void decode();
private:
string code;
};
void Paragraph::setCode() {
ifstream inFS;
inFS.open("Input");
getline(inFS , code);
inFS.close();
};
void Paragraph::getCode() {
cout << code << endl << endl << endl;
};
void Paragraph::decode() {
for (int i = 0; i < code.length(); i++) {
char characterHolder = code.at(i);
char newCharacter = characterHolder - 3;
characterHolder = newCharacter;
}
ofstream onFS;
onFS.open("Output");
onFS << code;
onFS.close();
};
int main()
{
Paragraph code;
code.setCode();
code.getCode();
code.decode();
code.getCode();
return 0;
}
the above code is intended to take a string of gobbledegoop my professor provided on a .txt file (Input.txt) and translate it into a coherent phrase by subtracting 3 from the ascii value of each character. the result is then supposed to be recorded into Output.txt. what are some reasons this may not be working?
>>232653
https://www.youtube.com/watch?v=pGXV1c7VcG0
bump
>>232653
Too lazy to check/run it, but you say you're want to read and write to a Input.txt and Output.txt. But in you code you open Input and Output.
>>232663
Just tried that but I got the same result as last time I ran it, a blank console window. Anything else I could be forgetting?
>>232666
add onFS.flush(); just before onFS.close();
>>232667
Same result as last time. I think it might be having trouble grabbing the string from the text file but idk why that would be.
>>232670
replace
characterHolder = newCharacter;
with
code[i] = newCharacter;
It works on my end (with the previous changes aswell).
>>232676
nope, no change
>>232677
I tried code.at(i) as well and still nothing
>>232679
PLease note that when running from visual studio it requires the Input.txt in the same folder as the root of the code and not in the debug/release folder.
>>232684
do you mean with the .cpp?
>>232686
Yeah, don't just drag it into the visual studio project, copy it to were the cpp files are
>>232684
https://www.youtube.com/watch?v=xos2MnVxe-c
It's working now! Thanks for the help!