}
bool findKey(string filename){
bool check = false;
string key = "%";
string line = "";
ifstream myfile;
myfile.open(filename, ios::in);
size_t pos;
while(myfile.good())
{
getline(myfile,line);
pos=line.find(key);
if(pos!=string::npos)
{
check = true;
break;
}
}
return check;
}
int getfileLength(string filename){
ifstream myfile (filename);
int val = 0;
int key = 0;string line;
if (myfile.is_open())
{
while (getline(myfile, line))
{
size_t pos = line.find('%');
if (pos != string::npos)
{
line = line.substr(0,pos);
}
val += line.length();
}
}
myfile.close();
return val;
}
int GetKey(string filename){
ifstream myfile (filename);
int val = 0;
int key = 0;string line;
if (myfile.is_open())
{
while (getline(myfile, line))
{
size_t pos = line.find('%');
if (pos != string::npos)
{
line = line.substr(pos+1);
}
}
}
myfile.close();
return atoi(line.c_str());
}
int main(){
string filename = "";
int key = 0;
bool choice = false;
int msg = 1;
ifstream myfile;
cout<<"Enter the name of text file in current directory: ";
cin>>filename;
myfile.open(filename);
if(!myfile){
cout<<"\nSorry the name of file "<<filename<<" you entered is not exist in current directory!";
return 0;
}else{
while(msg == 1){
msg = displayMenu(filename);
if(msg == 1)
cout<<"Your text file is not protected, first protect it by using option \"1\"\n\n";
if(msg == 2){
cout<<"\nYour text file is protected now!";
break;
}
else if(msg == 3){
cout<<"\nYour text file is already protected!";
break;
}
else if(msg == 4){
cout<<"The content of file are not changed after protection.";
break;
}else if(msg == 5){
cout<<"Alert! The content of file are changed after protection.";
break;
}