The first reading in of values to set up an array works just fine but when i try to do the second one it seems to skipthe while loop and give me 0's for my array
#include<iostream>
#include<cmath>
#include<string>
#include<fstream>
#include<vector>
usingnamespace std;
//======================================================================
int main () {
//FILLING DATA ARRAYS
// ask user for dat file
ifstream dat;
do {
cout << "Input filename where the raw data exist-->";
char filename [50];
cin.getline(filename,50);
dat.open(filename);
if (!dat.is_open())
cout << "File Does Not Exist!" << endl ;
} while (!dat.is_open());
double (*data)[3]= newdouble [15][3];
int x = 0 ;
double a,b,c,d,e,f;
while ( dat >> a >> b >> c){
data[x][0] = a;
data[x][1] = b;
data[x][2] = c;
cout << data[x][0] << endl; // to check
x++;
}
dat.close();
// fill values from giant text fill that I typed by hand!!
ifstream table;
do {
cout << "Input filename where the data table exist-->";
char file [50];
cin.getline(file,50);
table.open(file);
if (!table.is_open())
cout << "File Does Not Exist!" << endl ;
} while (!table.is_open());
double (*values)[6] = newdouble[500][6];
//array from 1967 table values are:
// jf , ji,l1,l2,f2,f4
x = 0 ;
// it will cout here
while (table >> a >> b >> c >> d >> e >> f){
values [x][0] = a;
values [x][1] = b;
values [x][2] = c;
values [x][3] = d;
values [x][4] = e;
values [x][5] = f;
cout << "loop" << endl; // this is not printing ??!?
cout << values [x][2] << endl;
x++;
}
//and it will cout here as well
table.close();
for (x=0 ; x<211 ; ++x){
cout << values [x][0] << endl; // returns all 0's
}
return (0);
}
I agree with cire. You should remove that line from the text file. The first extraction operation into a double would fail, which would cause line 63 to evaluate to false.