Fstream reading and writing question.

I know this is a really basic question, but if I wanted to use this code for a ceaser shift:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 {
    string input;
    do {
        getline(cin, input);
        string output = "";
        for(int x = 0; x < input.length(); x++)
        {
            output += caesar(input[x]);
        }
        cout << output << endl;
    } while (!input.length() == 0);
}

char caesar( char c )
{
    if( isalpha(c) )
    {
        c = toupper(c);
        c = (((c-65)+13) % 26) + 65;
    }
    return c;
}


Then how would I utilize this:

1
2
3
4
5
6
7
8
9
{
	ofstream fout("Text.txt");
	ifstream fin("Text.txt");
	int x;
	fin >> x;
	fout << x + 1 << endl;
	
	return 0;
}


To read the file "Text.txt" and undo the cipher with a command?
Is your encrypted stuff supposed to be 1 long number? or a string of words?
If it is a string you should input to a string then reverse the encryption.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <fstream>

void decrypt( std::string &text )
{
    //reverse the encryption here...
}

int main()
{
    std::ifstream in( "Text.txt" ); //encrypted txt
    std::string text;
    in >> text;
    decrypt( text );
}
Topic archived. No new replies allowed.