Trying to make a quick little tool in response to the FBI's request for assistance on cracking a code.. getting an error that takes me outside the scope of my program.. not sure what is causing the problemo. Maybe another set of eyes can help:
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <cctype>
#include <vector>
#include <algorithm>
using namespace std;
class Decode
{
public:
char menu();
void display();
void load(ifstream);
void eliminate();
void substitue();
void rand_shuffle();
void save(ofstream);
private:
vector<char> file;
};
int main()
{
Decode codebreak;
ifstream infile;
ofstream outfile;
string name;
char again = '\0';
cout << "Enter file location and name to open: ";
cin >> name;
//open file
infile.open(name.c_str());
//error handling
if(!infile.is_open())
{
cout << "\a\n\nError! File could not be opened! ";
cout << "\n(incorrect path... file possibly missing, renamed, or relocated) ";
exit(1);
}
//load file
codebreak.load(infile);
//main driver
do
{
again = codebreak.menu();
}while(again != '6');
//cleanup
infile.close();
return 0;
}
void Decode::load(ifstream infile)
{
char c = '\0';
file.clear();
while(infile)
{
infile.get(c);
file.push_back(c);
}
}
char Decode::menu()
{
char select = '\0';
cout << "\n\n\n1. Substitue";
cout << "\n2. Eliminate";
cout << "\n3. Random Shuffle\n";
cout << "\n4. Reload Original\n";
cout << "\n5. Save Results\n";
cout << "\n6. Quit\n\n";
cin >> select;
if(!isdigit(select) || isdigit < 1 && isdigit > 3)
{
cout << "\n\n\aInvalid entry, try again: ";
menu();
}
switch(select)
{
case 1: substitute();
break;
case 2: eliminate();
break;
case 3: rand_shuffle();
break;
case 4: load(ifstream);
break;
case 5: save(ofstream);
break;
}
display();
return select;
}
void Decode::substitute()
{
char target = '\0';
char sub = '\0';
cout << "\n\nEnter character ye' wish to sub: ";
cin >> target;
cout << "\n\nEnter substitution character: ";
cin >> sub;
replace(file.begin(), file.end(), target, sub);
}
void Decode::eliminate()
{
char target = '\0';
cout << "\n\nEnter character ye' wish to eliminate: ";
cin >> target;
remove(file.begin(), file.end(), target);
}
void Decode::rand_shuffle()
{
random_shuffle(file.begin(), file.end());
}
void Decode::save(ofstream outfile)
{
string name;
cout << "Enter save file path & document name: ";
cin >> name;
outfile.open(name.c_str());
for(int i=0, size=file.size(); i<size; i++)
{
outfile << file[i];
if(!(i%80))
{
outfile << endl;
}
}
outfile.close();
}
void Decode::display()
{
for(int i=0, size=file.size(); i<size; i++)
{
cout << file[i];
if(!(i%80))
{
cout << endl;
}
}
}