required.get(c);
}
cout << "The encryption is over";
required.close();
destined.close();
}
This program should encrypt/decrypt a message in a file, that the user should mention. It should have 3 functions, one to check the existence of the input file, the second should encrypt/decrypt each character and one to encrypt/decrypt the whole file. The thing is that the it keeps saying "The file does not exist". I don't know how to read it. Second problem is that the function to encrypt (encFile) does not work.
The thing is that the it keeps saying "The file does not exist". I don't know how to read it.
To fix this behavior change your checkExistingFile()
function as follows:
bool checkExistingFile(string& inFile)
{
ifstream required;
required.open(inFile.c_str());
while(required.fail())
{
cout<< "The file does not exist, please enter another file " <<
"(leave empty to abort)"<< endl;
cin >> inFile;
if(infile.empty()) { return false; }
required.open(inFile.c_str());
}
return true;
}
May be you should consider to give the user a chance to break the loop (eg giving an empty file name), and return false
then.
As others and you yourself mentioned there, are other problems with your code, I don't answer here.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.