Basically this code serves to take in an input file and convert all the "<" and ">" into "<" and ">" respectively. This works however, I cannot get it to convert the rest of the .txt file into the output file. Right now, it just works with the very first character in the text file.
How can I make this repeat until the end of the .txt file so that all characters in it are either converted or left alone?
I appreciate any and all help.
#include<fstream>
#include<iostream>
#include<cstdlib>
#include<stdlib.h>
using namespace std;
void checker (char next);
string ltreplace (char next);
string gtreplace (char next);
int main ()
{
ifstream inStream;
ofstream outStream;
string infileName, outfileName;
cout << "What file would you like to work with?" << endl;
cout << "Remember to include the file extension." << endl;
cin >> infileName;
cout << "What would you like to call the output?" << endl;
cin >> outfileName;
inStream.open(infileName.c_str()); //to connect with file
if (inStream.fail())
{
cout << "File open failed.\n";
getchar();
getchar();
exit(1);
}
char next;
string replace;
inStream >> next;
while (!inStream.eof()) //while loop not working
{
if (next == '<')
{
outStream.open(outfileName.c_str(), ios::app); //appends to the end of the file each time
outStream << ltreplace(next);
}
else if (next == '>')
{
outStream.open(outfileName.c_str(), ios::app); //appends to the end of the file each time
outStream << gtreplace(next);
}
else
{
outStream.open(outfileName.c_str(), ios::app); //appends to the end of the file each time
outStream << next;
}
inStream >> next;
}
return 0;
}
string ltreplace (char next)
{
string replacement;
replacement = "<";
return replacement;
}
string gtreplace (char next)
{
string replacement;
replacement = ">";
return replacement;
}