Re: File IO library issue
On May 4, 12:58 am, chiku <Bless2ash...@gmail.com> wrote:
I am working with file IO library and we are using google test
framework to test it .Being a beignner i am facing few issues.
My file open interface look like this
bool FileStream::Open(const string& fileName)
{
_stream->open(fileName.c_str());
if (_stream->is_open())
return true;
else
return false ;
Why not just:
return _stream->is_open() ;
?
}
where _stream is of fstream * type .
Just a secondary remark: it's not a good idea to start names
with an underscore. Technically, it's allowed if the following
character is not a capital, and the name isn't at global
namespace scope, but practically, you'll still get conflicts
with names defined by the system.
Above code seems to be giving false always when i called like
_fileName = "OpenWithValidFileName";
bool result = _fileStream->Open(_fileName);
where _fileName is of string type .
Any idea or thoughts?
Could be a lot of things. Does the file exist, for example? Or
do you have access rights to the current directory? (I'm also
a bit sceptical about the use of fstream. In my experience, it
is almost always preferable to use either ifstream or ofstream.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34