Assignment of variables

Hey,

I'm reading data from a file with three columns in three different variables, namely cola, colb, and colc. I need this in order to further analyze the data.

However, I have a problem after I read the data because I can not access the data at a given location e.g. cola[3].

I get the error:

error: invalid types 'double[int]' for array subscript

I would appreciate any help

My code is here,


#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_spline.h>

#include <gsl/gsl_matrix.h>

#include <iostream>
using std::cerr;
using std::cout;
using std::endl;

#include <fstream>
using namespace std;

#include <fstream>
using std::ifstream;

std::string line;

#include <typeinfo>



int j;
double ncola[34];

int main()
{
double cola, colb, colc;
ifstream in("airfoil.dat");

while(!in.eof())
{
in >> cola;
in >> colb;
in >> colc;

cout << cola << endl; / prints the whole column


}
ncola = cola; // this does not work
// cout << cola[3] + colb[3] << endl; // This does not work either!







//

return 0;

}





It's because ncola is defined as a pointer to a double, while cola, colb and colc are defined as doubles. Try writing:
double cola[34], colb[34], colc[34];
If I write double cola[34], colb[34], colc[34];

I get this error:

read.cpp:37:11: error: no match for 'operator>>' in 'in >> cola'


Topic archived. No new replies allowed.