Hi,
I am having difficulties compiling my code. I recently cleaned up my code by dividing class declarations into an appropriate classname.h file and the definitions of constructors and member functions in a classname.cpp file (using a static library). The problem arises with the
ofstream
object which I use to write out my data. Below is my Beam.h file (The paths specified for the other include files are correct)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#ifndef BEAM_H_
#define BEAM_H_
#include "/home/../Vega_lib/Source/VEGA_Include.h"
#include "/home/../Vega_lib/Source/VEGA_Classes.h"
class Beam {
public:
int beamNum,gantryAngle,collimatorAngle,couchAngle;
//control[0] = Zero if no carriage moves, else it is the number of the
// first control point in second carriage move
//control[1] = Total number of control points
int control[2];
//mu[0] = MU for first carriage move
//mu[1] = MU for second carriage move
float mu[2];
//The values for each Beam and it's maximum of two carriage moves
//xjaw[0] = Left jaw for first carriage move
//xjaw[1] = Right jaw for first carriage move
//xjaw[2] = Left jaw for second carriage move
//xjaw[3] = Right jaw for second carriage move
float xjaw[4], yjaw[4],SSD, isocentre[3];
//First index is control point
//Second index is leaf number
float **leaves,**MU;
float *cumulativeMeterset, *yLeafBoundary, *leafWidth, *area, *deltaMU;
int controlPoints, leafPairs;
char *s1;
Beam();
//Throws: Beam_Read_Fail
Beam(CPP_Sequence *seq);
void writeMUProfile(char *s1);
void initialiseMUProfile();
float getSegmentArea(const int i);
void calculateMUProfile();
~Beam();
};
#endif /* BEAM_H_ */
|
Here is the Beam.cpp file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#include "/home/.../Vega_lib/Source/Beam.h"
#include "/home/.../Vega_lib/Source/VEGA_Classes.h"
#include "/home/.../Vega_lib/Source/VEGA_Include.h"
#include<fstream>
#include<iostream>
...
void Beam::writeMUProfile(char *s1){
int j,k;
float test;
// write to file s1- define output fstream fout using fstream include file
ofstream fout;
fout.open(s1);
test=0.0f;
std::cout << "\n\nWriting MU profile \"" << s1 << "\" for gantry angle \"" << gantryAngle <<"\"\n";
fout << "X1 = " << xjaw[0] << "\tX2 = " << xjaw[1] << "\n";
fout << "Y2 = " << yjaw[0] << "\tY2 = " << yjaw[1] << "\n";
for (j=0;j<xjaw[1]-xjaw[0]; j++){
std::cout << j+1 << " ";
fout << "\n\nj = "<< j+1 << "\n";
for (k=0;k<yjaw[1]-yjaw[0];k++){
fout << MU[j][k] << "\\";
if ((MU[j][k]!=0.0)&& (MU[j][k]>mu[0])||(MU[j][k]<0.1)) test++;
}
}
if (test>0){
std::cout << "\nError writing MU profile!\n";
}
fout.close();
}
|
The ellipsis on line 7 are only there to indicate that the other constructor(s)/destructor and member functions are declared in the intervening space (but I don't think these are relevant to the problem)
My error messages are as follows:
Beam.cpp: In member function ‘void Beam::writeMUProfile(char*)’:
Beam.cpp:14: error: ‘ofstream’ was not declared in this scope
Beam.cpp:14: error: expected `;' before ‘fout’
Beam.cpp:15: error: ‘fout’ was not declared in this scope
I would really appreciate some help with this.