Connecting Tech Pros Worldwide Help | Site Map

fstream::open & seg fault

Manuel Maria Diaz Gomez
Guest
 
Posts: n/a
#1: Jul 22 '05
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::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
Guest
 
Posts: n/a
#2: Jul 22 '05

re: fstream::open & seg fault



"Manuel Maria Diaz Gomez" <Manuel.Maria.Diaz.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(inputFile.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


Manuel Maria Diaz Gomez
Guest
 
Posts: n/a
#3: Jul 22 '05

re: fstream::open & 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.Diaz.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(inputFile.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]


John Harrison
Guest
 
Posts: n/a
#4: Jul 22 '05

re: fstream::open & seg fault


On Tue, 20 Jul 2004 19:16:08 +0200, Manuel Maria Diaz Gomez
<Manuel.Maria.Diaz.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
Closed Thread