Your code is kind of funny. First you should open the file, read the file into an array, then close the file. Then you do all your work within the array. Then when you are finished, you open another file, write to that file, then close it.
Code:
#include <iostream.h> // For normal I/O
#include <fstream.h> // For ifstream/ofstream
#include <string.h> // For strlen()
int main()
{
char text[1024]; // Array to hold characters from infile
ifstream fin("whatever.txt"); // Infile
if( !fin )
{
cerr << "File could not be opened, sorry" << endl;
return 1;
}
while( fin >> text ) // Put the textfile in the array
cout << text;
fin.close(); // Close the file (we dont need it)
for( int i = 0; i < strlen(text); i++ )
{
switch( text[i] )
{
case 'a':
// do whatever
break;
default:
// do whatever
break;
}
}
ofstream fout("whatever2.txt"); // Open outfile
if( !fout )
{
cerr << "File could not be opened, sorry" << endl;
return 1;
}
fout << text; // Write to file
return 0; // ofstream's destructor closes the file
}
Good luck. I think your encryption idea is kind of impractical though. Go on google and look at Casaerian Encryption (aka rot13) and try and make a program around that. It is much more practical. And then after that, look at XOR encrypting