fstream::open & seg fault

Discussion in 'C++' started by Manuel Maria Diaz Gomez, Jul 20, 2004.

  1. Hi everybody,

    This is probably trivial, but I just can't see it.
    In the followinf function:

    /*-------------------------------------------------*/
    File::loadFile(string inputFile)
    /*-------------------------------------------------*/
    {
    ifstream myFile;

    myFile.open(inputFile.c_str());
    .....
    }

    I get a segmentation fault when invoking the open( fstream::eek:pen) function.
    I verified that inputFile.c_str() is returning the right value, so...

    Does someone has any hints about it?

    Regards
    Manuel


    --
    ========================================================================
    Manuel Diaz-Gomez | ATLAS Bldg. 32/SB-008 tel. +41 22 76 76304
    CERN EP Division
    CH-1211 Geneva 23
    SWITZERLAND
    ========================================================================
    Manuel Maria Diaz Gomez, Jul 20, 2004
    #1
    1. Advertising

  2. "Manuel Maria Diaz Gomez" <> wrote in message
    news:cdjddq$ca6$...
    > Hi everybody,
    >
    > This is probably trivial, but I just can't see it.
    > In the followinf function:
    >
    > /*-------------------------------------------------*/
    > File::loadFile(string inputFile)
    > /*-------------------------------------------------*/
    > {
    > ifstream myFile;
    >
    > myFile.open(inputFile.c_str());
    > .....
    > }
    >
    > I get a segmentation fault when invoking the open( fstream::eek:pen)

    function.
    > I verified that inputFile.c_str() is returning the right value, so...
    >
    > Does someone has any hints about it?
    >
    > Regards
    > Manuel
    >


    There is nothing wrong with the function you have posted. The error is
    somewhere else in your code. It's very hard to guess where or what it might
    be.

    john
    John Harrison, Jul 20, 2004
    #2
    1. Advertising

  3. I checked with gdb, and this is what I get (is definetly comming from the
    call to open ):

    [...]
    at
    /scratch/happi/GNU.LANG/gcc-alt-3.2/i686-pc-linux-gnu/libstdc++-v3/include/b
    its/ios_base.h:123
    123
    /scratch/happi/GNU.LANG/gcc-alt-3.2/i686-pc-linux-gnu/libstdc++-v3/include/b
    its/ios_base.h: No such file or directory.

    Somehow the file name I am passing as an argument is not being found. I
    tried everything (i.e. absolute path names, etc...)

    The paths are unix like(i.e /home/user), so I am passing arguments like :

    myFile.open("/home/user/myfile.txt")

    is this correct?

    Regards

    Manuel


    "Manuel Maria Diaz Gomez" <> wrote in message
    news:cdjddq$ca6$...
    > Hi everybody,
    >
    > This is probably trivial, but I just can't see it.
    > In the followinf function:
    >
    > /*-------------------------------------------------*/
    > File::loadFile(string inputFile)
    > /*-------------------------------------------------*/
    > {
    > ifstream myFile;
    >
    > myFile.open(inputFile.c_str());
    > .....
    > }
    >
    > I get a segmentation fault when invoking the open( fstream::eek:pen)

    function.
    > I verified that inputFile.c_str() is returning the right value, so...
    >
    > Does someone has any hints about it?
    >
    > Regards
    > Manuel
    >
    >
    > --
    > ========================================================================
    > Manuel Diaz-Gomez | ATLAS Bldg. 32/SB-008 tel. +41 22 76 76304
    > CERN EP Division
    > CH-1211 Geneva 23
    > SWITZERLAND
    > ========================================================================
    >
    >
    Manuel Maria Diaz Gomez, Jul 20, 2004
    #3
  4. On Tue, 20 Jul 2004 19:16:08 +0200, Manuel Maria Diaz Gomez
    <> wrote:

    > I checked with gdb, and this is what I get (is definetly comming from the
    > call to open ):
    >
    > [...]
    > at
    > /scratch/happi/GNU.LANG/gcc-alt-3.2/i686-pc-linux-gnu/libstdc++-v3/include/b
    > its/ios_base.h:123
    > 123
    > /scratch/happi/GNU.LANG/gcc-alt-3.2/i686-pc-linux-gnu/libstdc++-v3/include/b
    > its/ios_base.h: No such file or directory.
    >
    > Somehow the file name I am passing as an argument is not being found. I
    > tried everything (i.e. absolute path names, etc...)
    >
    > The paths are unix like(i.e /home/user), so I am passing arguments like :
    >
    > myFile.open("/home/user/myfile.txt")
    >
    > is this correct?
    >
    > Regards
    >
    > Manuel
    >


    Not being able to find a file does not cause a seg fault. Something else
    is wrong with your program.

    Something has gone wrong earlier and that is causing the seq fault to
    happen later on. It does not mean that there is something wrong with the
    way you are opening that file.

    Is the program small enough that you can post the whole program here? If
    not can you cut out the irrelevant parts of the code and post what is left
    here?

    john
    John Harrison, Jul 20, 2004
    #4
    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. Vinod

    Suprising seg fault!!!

    Vinod, Sep 27, 2003, in forum: C++
    Replies:
    3
    Views:
    459
    Ron Natalie
    Sep 27, 2003
  2. Corrine
    Replies:
    1
    Views:
    415
    Gianni Mariani
    Nov 27, 2003
  3. Armando
    Replies:
    6
    Views:
    735
    Armando
    Jan 29, 2004
  4. goktan
    Replies:
    4
    Views:
    2,012
    Howard
    Aug 2, 2004
  5. Riko Wichmann

    seg fault when doing shelve.open

    Riko Wichmann, Nov 23, 2004, in forum: Python
    Replies:
    0
    Views:
    303
    Riko Wichmann
    Nov 23, 2004
Loading...

Share This Page