There is a file which I opened and read the contents and closed.
When I visit again to try to read the file using another instance, is_open() is failing.
Below is the code which does it.
{
_decrptedResStr.clear();
string srcFile=sourceFile.toUtf8().constData();
ifstream ffin;
ffin.open(srcFile.c_str(),ios_base::in|ios_base::binary);
char keyToEncryption= keystring.toLatin1();
if(ffin.is_open())
{
char ch;
while(!(ffin.read(&ch,1).eof()))
{
ch ^= keyToEncryption;
_decrptedResStr.append(ch);
}
}
ffin.close();
return _decrptedResStr;
}
QString Decrypt::decryptFile(QString sourceFile,QChar keystring)
{
_decrptedResStr.clear();
string srcFile=sourceFile.toUtf8().constData();
ifstream ffin;
ffin.open(srcFile.c_str(),ios_base::in|ios_base::binary);
char keyToEncryption= keystring.toLatin1();
if(ffin.is_open())
{
char ch;
while(!(ffin.read(&ch,1).eof()))
{
ch ^= keyToEncryption;
_decrptedResStr.append(ch);
}
}
ffin.close();
return _decrptedResStr;
}
To copy to clipboard, switch view to plain text mode
Kindly let me know how to read the file again.
Bookmarks