help in these code please

that code is about a text editor program please tell me what's the wrong in the code
#include<iostream>
#include<string>
#include<iomanip>
#include<cctype>
#include<fstream>
using namespace std;
fstream myfile;
string filename;
string mystring;
string file;
void menu()
{
cout << endl;
cout << endl;
cout << "1. Add new txt to the end of the file" << endl;
cout << "2. Display the content of the file" << endl;

cout << "3. Empty the file" << endl;

cout << "4. Encrypt the file content" <<endl;

cout << "5. Decrypt the file content" <<endl;

cout << "6. Merge another file" << endl;

cout << "7. Count the number of lines in the file" <<endl;

cout << "8. Search for a word in the file" << endl;

cout << "9. Count the number of times a word exists in the file" << endl;

cout << "10. Turn the file content to upper case" << endl;

cout << "11. Exit" << endl;

cout << endl;//write newline.
cout << endl;//write newline.
}
void add()
{
ofstream myfile1;//ofstream constructor opens myfile1.
myfile1.open(filename.c_str(),ios::out|ios::app);
.
string mystring2;
cout << "Enter the string & end it with * " << endl;//copy enter the string &end it with*.
getline(cin,mystring2);
myfile1<< mystring2;
myfile1.close();
}

void display()
{
fstream myfile;

myfile.open(filename.c_str(),ios::in);
cout<<"\t"<<filename<<endl;
while(!myfile.eof())
{
char x ;
getline(myfile,mystring);
int y= mystring.size();
for(int i=0;i<y;i++)
{
x=mystring[i];
cout<<x;
}
cout<<endl;
}
cout<< endl;
myfile.close();
}
void empty()
{
ifstream myfile;
myfile.open(filename.c_str(),ios::trunc|ios::out);

myfile.clear();
}

void encrypt()
{

int i=0,j=0;
string mystring3;
ifstream infile;
ofstream outfile;
infile.open(filename.c_str(),ios::in);
while(infile.get(mystring3[i]))
{
mystring3[i]++;
i++ ;
}
outfile.open(filename.c_str(),ios::out);
while(mystring3[j] != '\0')
{
outfile<<mystring3[j];
j++;
}
cout<<endl;
cout<<"the file is encrypted & secured\n";//copy the file is encrypted & seured.
outfile.close();
}
void decrypt()
{
//variables declaration.
int i=0,j=0;//intialize two variables i=0 and j=0.
string mystring3;
ifstream infile;
ofstream outfile;
infile.open(filename.c_str(),ios::in);//ifstream constructor opens infile.
while(infile.get(mystring3[i]))
{
mystring3[i]--;//decreament mystring3[i].
i++ ;//increament variable i.
}//end first while loop.
outfile.open(filename.c_str(),ios::out);//ofstream constructor opens infile.
while(mystring3[j] != '\0')
{
outfile<<mystring3[j];//write a string mystring3[j].
j++;//increament variable j.

}//end second while loop.
cout<<endl;//write a newline.
cout<<"thefile is decrypted \n";//copy thefile is decrypted.
}//end void function.
void merge()
{
string mystring2;//store a string mystring2 in the memory.
string filename2;//store a string filename2 in the memory.
fstream myfile2;
//ifstream myfile2.
//ofstream myfile2.
ofstream myfile1;
cout<<"enter the second file that will be megred\n";
//copy enter the second file that will be megred.
cin>>filename2;//read filename2 from the user.
myfile2.open(filename2.c_str(),ios::in);//ofstream constructor opens infile.
if(myfile2.fail())
cout<<"Invaild File Name\n";//copy invalid file name.
else
{
getline(myfile2,mystring2);
myfile1.open(filename.c_str(),ios::out|ios::app);
//ofstream constructor opens and appends.
myfile1<<mystring2;//write mystring2.
myfile1.close();//end getline function.
cout<< endl;//write newline.
cout<<"the two files are merged";//copy the two files are merged.
}//end the condition else.
}//end void function.
void countlines()
{
int count=0;//intialize vaiable count=0.
while(!myfile.eof())
{
int z=myfile.get();//intialize vaiable z=myfile.get().
getline(myfile,mystring);
mystring.find("\n",z);
count++;//increament variable count.
}//end while loop.
cout<<count<<endl;//write count.
}//end void function.

void countwords()
{
string word;//store a string word in the memory.
int count=1;//intialize avariable count=1.
cout<<"please enter the word that you want to find\n";
//copy please enter the word that you want to find.
cin>>word;//read word from the user.
while(!myfile.eof())
{
int z=myfile.get();
getline(myfile,mystring);
mystring.find(word,z);
count++;//increament variable count.
}
cout<<count<<endl;//write count.
}//end void function.
void searchword()
{
string word;//store string word in the memory.
int count=0;//
cout<<"please enter the word that you want to find\n";
cin>>word;//read word.
while(!myfile.eof())
{
int z=myfile.get();
getline(myfile,mystring);
mystring.find(word,z);//find a word in the text when z=myfile.get().
count++;//increament variable count.
}//end the while loop.

if(count >= 0)//indicate the condition if the count greater or equal 0.
cout << "The word is found " << endl;//copy the word is found on the screen.
else
cout << "The word is not found " << endl;//copy the word is not found.
}//end void function.
void capital()
{
//variables declaration.
int j=0,i=0;//intialize two variables i=0 and j=0.
string string1;//store string1 in the memory.
ifstream infile;
ofstream outfile;
infile.open(filename.c_str(),ios::in);//ifstream constructor opens infile.
while(!infile.eof())
{
infile>>string1[i];//read string1[i] from the user.
i++;//increament variable i.
}//end the first while loop.
outfile.open(filename.c_str(),ios::out);//ofstream constructor opens outfile.
while(string1[j] != '\0')
{
outfile<<static_cast<char>(toupper(string1[j]));
j++;//increament variable j.
}//end the second while loop.
}//end void function.
int main()
{
//copy welcome to the legend text editor.
cout << "###############Welcome to the legend Text Editor###############" << endl;


cout << "please enter the file name " << endl;//copy please enter the file name on the screen.
cin >> filename;//read filename from the user.
myfile.open(filename.c_str());
if(myfile.fail())
{
//copy this is a new file.i created it for you.
cout << "This is a new file.Icreated it for you " << endl;
myfile.open(filename.c_str(),ios::out);//ofstream constructor opens the file.
}
else
cout << "This file already Exists " << endl;//copy this file already exists on the screen.
myfile << mystring;//read mystring from the user.
menu();

int choice;//intialize variable choice.

do
{
cout << "enter your choice" << endl;//copy enter your choice on the screen.
cin >> choice;//read choice from the user.
if(choice == 11)
break;
switch(choice)
{
case 1:
add();// call the void add function.
break;
case 2:
display();//call the void display function.
break;
case 3:
empty();//call the void empty function.
break;
case 4:
encrypt();//call the void encrypt function.
break;
case 5:
decrypt();//call the void decrypt function.
break;
case 6:
merge();//call the void merge function.
break;
case 7:
countlines();//call the void countlines function.
break;
case 8:
searchword();//call the void searchword function.
break;
case 9:
countwords();//call the void countwords function.
break;
case 10:
capital();//call the void capital function.
break;
}
menu();
}while(choice != 11);//exit program if the choice is 11.
//end the switch condition


myfile.close();
system("pause");
return 0;//indicate that the program ended successfully.
}//end main function.
I compiled your code in VS 2005 after i fixed a nessary "." symbol in your code.
it works fine
1
2
3
4
ofstream myfile1;//ofstream constructor opens myfile1.
myfile1.open(filename.c_str(),ios::out|ios::app);
.
string mystring2;
Topic archived. No new replies allowed.