My question is about variables defined into classes. I show you my problem.
I have defined this class:
class Measure {
int N;
double measure_set[];
char nomefile[];
double T;
public:
void get( );
void printall( );
double mean( );
double thermal_comp( );
};
I would like method get to do the following:
- read numbers from a .dat file and save into measure_set array;
- read user input and save it into variable T;
Here is what I've done:
void Measure::get()
{
cout << "Insert filename:" << endl;
cin >> nomefile;
cout << endl;
cout << nomefile << endl;
cout << endl;
int M=0;
int nmax=50;
ifstream f;
f.open(nomefile);
while(M<nmax)
{
f >> measure_set[M];
if(f.eof())
break;
M++;
}
f.close();
N=M+1;
cout << "Insert temperature:" << endl;
cin >> T;
cout << endl;
}
What happens is that I've noticed that T is memorized in measure_set[0]
. Why this happens and how can I write a working code? I'm not that expert in C++, using this only for computation purposes, although I could solve my problem in other ways I would like to learn how to make this work in C++. Thanks a lot!