Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > fstream::open & seg fault

Reply
Thread Tools

fstream::open & seg fault

 
 
Manuel Maria Diaz Gomez
Guest
Posts: n/a
 
      07-20-2004
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: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
================================================== ======================


 
Reply With Quote
 
 
 
 
John Harrison
Guest
Posts: n/a
 
      07-20-2004

"Manuel Maria Diaz Gomez" <(E-Mail Removed)> wrote in message
news:cdjddq$ca6$(E-Mail Removed)...
> 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: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


 
Reply With Quote
 
 
 
 
Manuel Maria Diaz Gomez
Guest
Posts: n/a
 
      07-20-2004
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" <(E-Mail Removed)> wrote in message
news:cdjddq$ca6$(E-Mail Removed)...
> 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: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
> ================================================== ======================
>
>



 
Reply With Quote
 
John Harrison
Guest
Posts: n/a
 
      07-20-2004
On Tue, 20 Jul 2004 19:16:08 +0200, Manuel Maria Diaz Gomez
<(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
seg-fault on vector-auto-reserve Matthias Kaeppler C++ 2 02-27-2005 10:01 PM
seg fault on different linux boxes with C++. goktan C++ 4 08-02-2004 03:25 PM
seg fault because stdexcept.cc not found? Corrine C++ 1 11-27-2003 06:15 AM
Suprising seg fault!!! Vinod C++ 3 09-27-2003 02:43 PM
Seg fault while running C script as non root forrest stanley C Programming 10 06-27-2003 04:08 PM



Advertisments