reading data problems

Y

Yesim

Hello,

I am trying to read two-dimensional float data into C++, but am
getting a segmentation fault error message. This happens in g++
compiler versions 2.95.2 and 3.1, but not on version 3, each in three
different servers. I need to compile in the latest version. Below I
attach the beginning of the code giving the problem:

# include <iostream>
# include <fstream>

int main()
{
std::ifstream input ; (this is where the problem occurs, i then
go on)

...

input.open("filename") ;

...

}

and so on. Is there a more general/accepted way to do this? Please let
me know if you need more detail. Thanks a lot,
Yesim
 
M

Mike Wahler

Yesim said:
Hello,

I am trying to read two-dimensional float data into C++, but am
getting a segmentation fault error message. This happens in g++
compiler versions 2.95.2 and 3.1, but not on version 3, each in three
different servers. I need to compile in the latest version. Below I
attach the beginning of the code giving the problem:

Why just the 'beginning?'. It would help us help you
better if you'd post the smallest, complete, compilable
program that exhibits the problem.
# include <iostream>
# include <fstream>

int main()
{
std::ifstream input ; (this is where the problem occurs, i then
go on)

What problem? Does a 'segmentation fault' occur at this
point? How do you know?

Your code to this point is perfectly valid.
...

input.open("filename") ;

This line is OK too. (But you should check the stream
state before attempting to read from the file).
...

}

and so on. Is there a more general/accepted way to do this?

Do what? All your posted code does is create a stream
object and attempt to open a file. What you have is the way
to do it.
Please let
me know if you need more detail. Thanks a lot,

We need a complete program, and a more specific description
of what it's supposed to do, and what it actually does.

-Mike
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top