fstream::open & seg fault

  • Thread starter Manuel Maria Diaz Gomez
  • Start date
M

Manuel Maria Diaz Gomez

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
========================================================================
 
J

John Harrison

Manuel Maria Diaz Gomez said:
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
 
M

Manuel Maria Diaz Gomez

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
 
J

John Harrison

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
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top