PDA

View Full Version : Unable to open a file which was previously opened and close using ifstream in ios



ejoshva
24th February 2015, 10:19
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.


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::b inary);

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;
}

Kindly let me know how to read the file again.

ejoshva
24th February 2015, 14:13
Got the issue resolved.
Issue was with the ini file. Haven't added the group name in the .ini file