473,386 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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(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
================================================== ======================
Jul 22 '05 #1
3 7048

"Manuel Maria Diaz Gomez" <Ma*********************@cern.ch> wrote in message
news:cd**********@sunnews.cern.ch...
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


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
Jul 22 '05 #2
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" <Ma*********************@cern.ch> wrote in message
news:cd**********@sunnews.cern.ch...
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
================================================== ======================

Jul 22 '05 #3
On Tue, 20 Jul 2004 19:16:08 +0200, Manuel Maria Diaz Gomez
<Ma*********************@cern.ch> 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
Jul 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Marc Schellens | last post by:
fstream.open( name, mode) fails fstream.fail() returns true. How can I find out what went wrong? (ie. file does not exist for reading, permissions...) thanks, marc
14
by: Mike - EMAIL IGNORED | last post by:
Using RH9, from this fragment: fstream theStream_; string fPath = "myFile"; int mode = O_EXCL | O_CREAT; theStream_.open(fPath.c_str(),mode); I get the failure shown below. ...
7
by: Computer Whizz | last post by:
Hi, I was just wondering if someone would like to comment on these two issues. I had a 15 minute wander around some sites and was curious about loading files (plain ASCII I think will do for a...
3
by: John R. Delaney | last post by:
If I try to declare an object of type fstream (or ofstream), I run into a compilation error refering to an __something function or variable. Please note, I am including <fstream>, not <fstream.h>....
5
by: derek | last post by:
I see this has come up over and over again in the past... that programmers waste hours of confusion when using a fstream object to open, read/write, close then attempt to open another file (or the...
5
by: ehui928 | last post by:
The following program is used to open a file in mode both read and append, but it has a problem that the file can't be opened. #include <iostream> #include <fstream> #include <cstdlib> ...
3
by: Belebele | last post by:
The code below does not cause an assertion failure. fstream f; f.open("myfile"); assert( f.is_open() ); However, the one below does fail the assert:
6
by: wiso | last post by:
My problem is this (from: http://www.cplusplus.com/ref/iostream/fstream/open.html) #include <fstream> using namespace std; int main() { fstream f;
1
by: massdeletion101 | last post by:
I'm a newbie at manipulating external files. Is there any way to specify a path to the file with C++? It thinks that the path in the file name string is filled with unrecognisable escape sequences....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.