File IO library issue

C

chiku

Hi ,
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 ;
}
where _stream is of fstream * type .

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?


Chiku
 
V

Victor Bazarov

chiku said:
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 ;
}
where _stream is of fstream * type .

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?

Does the file "OpenWithValidFileName" actually exist?

V
 
J

James Kanze

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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top