rot13

Write a C++ program that asks the user for the name of an input file and translates the contents of that input file using ROT13.

Your main function should be responsible for reading the input file and coordinating calls to a functon named ROT13 that will do the translation for each character and WriteTranslatedChar that will write the translated character to a secondary file, the ROT13 function should be defined with a reference parameter that will be the initial character as input and the translated character as output.

The second function WriteTranslatedChar will have two parameters, the translated character and a reference to an ifstream data type for a secondary file named "output.ROT13", and write that translated character to this file.

This is what I have so far
Please Help It's due Monday.
How can I tell if it translated the file and created the output file,
I feel really lost.


#include<iostream>
#include<fstream>

using namespace std;


char Rot13(char to_be_translated)
{
if(to_be_translated>='A' && to_be_translated<='Z')
{
return (to_be_translated-'A'+13)%26+'A';
}
else if(to_be_translated>='a' && to_be_translated<='z')
{
return (to_be_translated-'a'+13)%26+'a';
}
return to_be_translated;
}

void WriteTranslatedCharacter(char translated_character, ofstream& output)
{
output << translated_character;
}

int main()
{
string input_file;

cout <<"Enter the name of input file:";
cin >> input_file;
cout << endl;

ifstream infile(input_file.c_str());
ofstream outfile("output.rot13");

if(!infile)
{
cout <<"Unable to open file" << endl;
return 0;
}

char char_from_file = infile.get();;
while(!infile.eof())
{
WriteTranslatedCharacter(Rot13(char_from_file), outfile);
char_from_file = infile.get();
}

infile.close();
outfile.close();
return 0;
}

I works fine. You can check the result at http://www.rot13.com/

How can I tell if it translated the file and created the output file

Just create a little function that reads the file and prints it on the screen.
When I try to build it using Visual studio it gives me this error

Severity Code Description Project File Line Suppression State
Error C2679 binary '>>': no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) Chapter8Exercise2 c:\users\robert\desktop\chapter8exercise2\chapter8exercise2\ch8_ex2.cpp 30

on this line

cin >> input_file;

the error is >> ?

I feel so lost!
I added

#include<string>

and I think it's working
Topic archived. No new replies allowed.