ROT13 program problems

closed account (2EURX9L8)
I am trying to make a simple program in c++ that reads text from a txt file, decodes it using ROT13, then prints the decoded message to another txt file.

I am getting pretty lost and what I have now just loops infinitely.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<iostream>
#include<fstream>
#include<string>


using namespace std;


int main(){

	ifstream inputstuff;
	ofstream outputstuff;

	inputstuff.open("secretMessage.txt");
	outputstuff.open("decodedMessage.txt");

	char c=0;
	inputstuff.get(c);

	
        while (!inputstuff.eof()){
                if (c>='a' && c<='m') c += 13;
                else if (c >= 'n' && c <= 'z') c -= 13;
                else if (c >= 'A' && c <= 'M') c += 13;
                else if (c >= 'N' && c <= 'Z') c -= 13;
                inputstuff.get(c);

		cout<<c;
}
return 0;
}
                     



I am just trying to use cout for now so I can see what is going on in a console. If any one could point me in the right direction I would be most grateful.
Last edited on
Correct usage of eof():

1
2
3
4
5
6
7
8
9
10
11
if(!(inputstuff >> foo)) 
{
   if (inputstuff.eof()) 
   {
      cout << "read failed due to end of file\n";
   } 
   else
   {
      cout << "read failed due to something other than end of file\n";
   }
}


U can loop on while(inputstuff)
Last edited on
Topic archived. No new replies allowed.