File IO library issue

Discussion in 'C++' started by chiku, May 3, 2009.

  1. chiku

    chiku Guest

    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
     
    chiku, May 3, 2009
    #1
    1. Advertising

  2. chiku 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 ;
    > }
    > 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
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, May 4, 2009
    #2
    1. Advertising

  3. chiku

    James Kanze Guest

    On May 4, 12:58 am, chiku <> 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:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, May 4, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jothi

    issue using Load Library

    Jothi, Oct 18, 2005, in forum: Java
    Replies:
    3
    Views:
    891
    Roedy Green
    Oct 19, 2005
  2. Replies:
    0
    Views:
    1,363
  3. library issue

    , May 5, 2005, in forum: C++
    Replies:
    1
    Views:
    358
    Victor Bazarov
    May 5, 2005
  4. Replies:
    10
    Views:
    1,086
    William Ahern
    Feb 20, 2007
  5. Srini
    Replies:
    11
    Views:
    988
    Arne Vajhøj
    Jun 1, 2008
Loading...

Share This Page