c++ error

I created this code so that it would code anthing inside of a file that you have.
heres the code with cin instead of a file, it works. after that is the code with the file that should run

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

string subb;
int x;

int main()
{
char filename[50];
cout<<"Welcome to codemaker! please put the file that you would\nlike to code in the file that this came with.";
cout<<"\n\nWhat is the name of your file?";
cin>>filename;
ifstream openfile;
openfile.open(filename);
string code[10000];
for(int u=0; u<10000; u++)
{
getline(openfile, code[u]);
x=code.length();
for (int z=0; z<=x; z++)
{
subb.assign(code.substr(z,1));
if (subb=="a")
{
code.replace(z, 1, "c");
}
if (subb=="c")
{
code.replace(z, 1, "e");
}
if (subb=="e")
{
code.replace(z, 1, " ");
}
if (subb=="g")
{
code.replace(z, 1, "i");
}
if (subb=="i")
{
code.replace(z, 1, "k");
}
if (subb=="k")
{
code.replace(z, 1, "m");
}
if (subb=="m")
{
code.replace(z, 1, "o");
}
if (subb=="o")
{
code.replace(z, 1, "q");
}
if (subb=="q")
{
code.replace(z, 1, "s");
}
if (subb=="s")
{
code.replace(z, 1, "u");
}
if (subb=="u")
{
code.replace(z, 1, "w");
}
if (subb=="w")
{
code.replace(z, 1, "y");
}
if (subb=="y")
{
code.replace(z, 1, "a");
}
if (subb=="b")
{
code.replace(z, 1, "d");
}
if (subb=="d")
{
code.replace(z, 1, "f");
}
if (subb=="f")
{
code.replace(z, 1, "h");
}
if (subb=="h")
{
code.replace(z, 1, "j");
}
if (subb=="j")
{
code.replace(z, 1, "l");
}
if (subb=="l")
{
code.replace(z, 1, "n");
}
if (subb=="n")
{
code.replace(z, 1, "p");
}
if (subb=="p")
{
code.replace(z, 1, "r");
}
if (subb=="r")
{
code.replace(z, 1, "t");
}
if (subb=="t")
{
code.replace(z, 1, "v");
}
if (subb=="v")
{
code.replace(z, 1, "x");
}
if (subb=="x")
{
code.replace(z, 1, "z");
}
if (subb=="z")
{
code.replace(z, 1, "b");
}
if (subb==" ")
{
code.replace(z, 1, "g");
}
}
}
openfile.close;

ofstream savefile(filename);
{
for (int up=0; up<=u; up++)
{
savefile<< code[up];

}
}
}


#include <iostream>
#include <string>
#include <fstream>

using namespace std;

string subb;
int x;

int main()
{
char filename[50];
cout<<"Welcome to codemaker! please put the file that you would\nlike to code in the file that this came with.";
cout<<"\n\nWhat is the name of your file?";
cin>>filename;
ifstream openfile;
openfile.open(filename);
string code[10000];
for(int u=0; u<10000; u++)
{
getline(openfile, code[u]);
x=code.length();
for (int z=0; z<=x; z++)
{
subb.assign(code.substr(z,1));
if (subb=="a")
{
code.replace(z, 1, "c");
}
if (subb=="c")
{
code.replace(z, 1, "e");
}
if (subb=="e")
{
code.replace(z, 1, " ");
}
if (subb=="g")
{
code.replace(z, 1, "i");
}
if (subb=="i")
{
code.replace(z, 1, "k");
}
if (subb=="k")
{
code.replace(z, 1, "m");
}
if (subb=="m")
{
code.replace(z, 1, "o");
}
if (subb=="o")
{
code.replace(z, 1, "q");
}
if (subb=="q")
{
code.replace(z, 1, "s");
}
if (subb=="s")
{
code.replace(z, 1, "u");
}
if (subb=="u")
{
code.replace(z, 1, "w");
}
if (subb=="w")
{
code.replace(z, 1, "y");
}
if (subb=="y")
{
code.replace(z, 1, "a");
}
if (subb=="b")
{
code.replace(z, 1, "d");
}
if (subb=="d")
{
code.replace(z, 1, "f");
}
if (subb=="f")
{
code.replace(z, 1, "h");
}
if (subb=="h")
{
code.replace(z, 1, "j");
}
if (subb=="j")
{
code.replace(z, 1, "l");
}
if (subb=="l")
{
code.replace(z, 1, "n");
}
if (subb=="n")
{
code.replace(z, 1, "p");
}
if (subb=="p")
{
code.replace(z, 1, "r");
}
if (subb=="r")
{
code.replace(z, 1, "t");
}
if (subb=="t")
{
code.replace(z, 1, "v");
}
if (subb=="v")
{
code.replace(z, 1, "x");
}
if (subb=="x")
{
code.replace(z, 1, "z");
}
if (subb=="z")
{
code.replace(z, 1, "b");
}
if (subb==" ")
{
code.replace(z, 1, "g");
}
}
}
openfile.close;

ofstream savefile(filename);
{
for (int up=0; up<=u; up++)
{
savefile<< code[up];

}
}
}
Topic archived. No new replies allowed.