B
Bernhard Hidding
Hi there,
I want to read an ASCII file ("magnetfile.dat") consisting of doubles into
an array. The ASCII file looks like this:
1.0 1.0 1.0 0.5
2.0 1.0 1.0 0.4
usw.
My code:
double magnefield[200]; //this is the array
int i;
ifstream magnetic_field_array;
magnetic_field_array.open("magnetfile.dat");
for (i=0;i<20;i++)
{
magnetic_field_array >> magnefield; //should write 1.0 , 1.0, 1.0,
0.5 ... into the array
}
magnetic_field_array.close();
I use g++ on SuSE 9.1. The executable runs, however, when I print out my
array magnefield, strange numbers appear. What is going wrong?
By the way: my file "magnetfile.dat" is in my working directory. However,
g++ does not give our an error message if I remove the file, so I am not
sure if the program finds the file after all. Might this be the problem?
Thanks for your help,
Bernhard
I want to read an ASCII file ("magnetfile.dat") consisting of doubles into
an array. The ASCII file looks like this:
1.0 1.0 1.0 0.5
2.0 1.0 1.0 0.4
usw.
My code:
double magnefield[200]; //this is the array
int i;
ifstream magnetic_field_array;
magnetic_field_array.open("magnetfile.dat");
for (i=0;i<20;i++)
{
magnetic_field_array >> magnefield; //should write 1.0 , 1.0, 1.0,
0.5 ... into the array
}
magnetic_field_array.close();
I use g++ on SuSE 9.1. The executable runs, however, when I print out my
array magnefield, strange numbers appear. What is going wrong?
By the way: my file "magnetfile.dat" is in my working directory. However,
g++ does not give our an error message if I remove the file, so I am not
sure if the program finds the file after all. Might this be the problem?
Thanks for your help,
Bernhard