fstream::open & seg fault

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Manuel Maria Diaz Gomez

    fstream::open & seg fault

    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(inp utFile.c_str()) ;
    .....
    }

    I get a segmentation fault when invoking the open( fstream::open) 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
    =============== =============== =============== =============== ============


  • John Harrison

    #2
    Re: fstream::open & seg fault


    "Manuel Maria Diaz Gomez" <Manuel.Maria.D iaz.Gomez@cern. ch> wrote in message
    news:cdjddq$ca6 $1@sunnews.cern .ch...[color=blue]
    > 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(inp utFile.c_str()) ;
    > .....
    > }
    >
    > I get a segmentation fault when invoking the open( fstream::open)[/color]
    function.[color=blue]
    > I verified that inputFile.c_str () is returning the right value, so...
    >
    > Does someone has any hints about it?
    >
    > Regards
    > Manuel
    >[/color]

    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


    Comment

    • Manuel Maria Diaz Gomez

      #3
      Re: fstream::open &amp; seg fault

      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" <Manuel.Maria.D iaz.Gomez@cern. ch> wrote in message
      news:cdjddq$ca6 $1@sunnews.cern .ch...[color=blue]
      > 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(inp utFile.c_str()) ;
      > .....
      > }
      >
      > I get a segmentation fault when invoking the open( fstream::open)[/color]
      function.[color=blue]
      > 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
      > =============== =============== =============== =============== ============
      >
      >[/color]


      Comment

      • John Harrison

        #4
        Re: fstream::open &amp; seg fault

        On Tue, 20 Jul 2004 19:16:08 +0200, Manuel Maria Diaz Gomez
        <Manuel.Maria.D iaz.Gomez@cern. ch> wrote:
        [color=blue]
        > 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
        >[/color]

        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

        Comment

        Working...