I am trying to fill a dynamic array from a text file but I keep getting errors this is my first attempt at doing something with dynamic arrays so im not too sure on what is going wrong!
#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;
data = newdouble [15][3];
int x;
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][2] << endl; // to check
x++;
}
return (0);
}
the errors are (line numbers are incorrect):
dhilchie@mars 1:23pm ->gpp vbays.cpp
vbays.cpp: In function ‘int main()’:
vbays.cpp:62: error: cannot convert ‘double (*)[3]’ to ‘double*’ in assignment
vbays.cpp:68: error: invalid types ‘double[int]’ for array subscript
vbays.cpp:69: error: invalid types ‘double[int]’ for array subscript
vbays.cpp:70: error: invalid types ‘double[int]’ for array subscript
dhilchie@mars 1:26pm ->
//double * data;
//data = new double [15][3];
// type of data is 'pointer to array of 3 double'
// an array, where each element is of type 'double[3]' is being allocated
// new returns a pointer to the first element; ie a pointer to double[3]
double (*data)[3] = newdouble [15][3];