I have data which has been processed and stored into a data structure, data_base, defined by 3 classes. The data has the following form with thousands of lines:
//energy, energy_loss, x_pos, y_pos, z_pos
6.452757 1.531386 -0.393354 1.103488 107.863468
5.078611 1.374147 -0.413115 1.116262 108.052493
3.794508 1.284103 -0.427070 1.128054 108.200915
2.464638 1.329870 -0.428052 1.142637 108.316191
0.960768 1.503870 -0.430519 1.152415 108.398472
0.000000 0.960768 -0.430475 1.154462 108.421579
6.625408 1.402283 0.322641 1.591752 104.882207
5.260457 1.364951 0.329267 1.607333 105.077547
3.976761 1.283696 0.333221 1.618724 105.231689
2.713429 1.263332 0.334553 1.625161 105.352229
1.264016 1.449413 0.330530 1.630337 105.441501
0.000000 1.264016 0.329969 1.632061 105.477167
6.212022 1.475655 -1.736159 1.360011 105.789436
4.901267 1.310755 -1.699868 1.369173 105.968425
3.686299 1.214968 -1.669443 1.380009 106.109465
2.358059 1.328240 -1.640704 1.383770 106.219239
0.922748 1.435311 -1.620864 1.386110 106.296610
0.000000 0.922748 -1.614663 1.386681 106.317501
.
.
.
This data is stored into a vector, dm_data::data_base which can be defined by the following 3 classes.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
class dm_Step
{
public:
float m_energy;
float m_energy_loss;
float m_xpos;
float m_ypos;
float m_zpos;
void print()
{
ofstream test_file("C:\\Documents\\test.txt");
test_file << m_energy << " " << m_energy_loss << " " << m_xpos << " " << m_ypos << " " << m_zpos << endl;
}
};
|
1 2 3 4 5 6 7 8 9 10 11 12 13
|
class dm_Track
{
public:
vector<dm_Step> m_track;
void print()
{
ofstream test_file("C:\\Documents\\test.txt");
for(int c = 0; c < m_track.size(); c++)
m_track.at(c).print();
}
};
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
class dm_Data
{
public:
vector<dm_Track> m_data;
void print()
{
for(int c = 0; c < m_data.size(); c++)
{
ofstream test_file("C:\\Documents\\test.txt");
m_data.at(c).print();
test_file << endl;
}
}
};
|
Using this data structure for example,
data_base.m_data.at(0).m_track.at(0).m_energy = 6.452757 which is the energy value as seen on the first line of the data.
As you can see I also included a print() function to output the data to a file, test.txt, when called. When I try to use this print() function, nothing is output to my text file:
1 2 3 4 5 6 7 8 9 10 11
|
void main
{
.
.
.
data_base.print()
.
.
.
}
|
What am I doing wrong? Am I correctly using the function defined in my classes to output this data?