Reading from a File into Three Arrays

The following is a text file that has to be converted into three arrays dc[], gt[], and snr[]
the numbers for the gt array are in bold.


"This data file is arranged as follows
The number on a lone line is the dopant concentration in atoms/cucm x 1.00E-17
The next five lines are the gt in nanometers
followed by the signal to noise ratio in decibels
1.1
2 35.1
2.2 36.3
2.4 37.2
2.6 38.1
2.8 39.5
1.2
2 37.2
2.2 39.5
2.4 41.2
2.6 42.3
2.8 46.2
1.5
2 41.2
2.2 44.2
2.4 48.2
2.6 50.3
2.8 53.4
1.7
2 48.2
2.2 51.2
2.4 55.6
2.6 60.2
2.8 65.2
1.9
2 55.6
2.2 62.3
2.4 66.2
2.6 72.5
2.8 78.6
"

I understand that some sort of loop must be used in order to move all of the numbers above into three separate arrays, however the only way I can think of attempting to move it into the three separate arrays is as follows..
"

using namespace std;
#include<iostream>
#include<cmath>
#include<fstream>
#include<iomanip>


int main() {

char skiplines [210];
int i;
double dc[4], gt[25], snr[25];

ifstream indata("noisedata.txt");
for (i=0;i<4;i++)
{
indata.getline (skiplines, 210);
cout<<skiplines<<endl; //This has skipped up to line 5
}
for (i=4;i<=33;i++)
{
if (i==4);
indata>>dc[0];
cout<<dc[0];
if (i==10);
indata>>dc[1];
if (i==16);
indata>>dc[2];
if (i==22);
indata>>dc[3];
if (i==28);
indata>>dc[4];
if (i!=4||10||16||22||28);
indata>>gt[i]>>snr[i];

}

system("pause");
return 0;
}
"
If anyone could help me with figuring out how to input the numbers from the file into the three arrays that would be greatly appreciated.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int i = 0;
vector<float> dc,gt,snr;
float input;
while(!indata.eof())
{
    if(!(i%11))
    {
         indata>>input;
         dc.push_back(input);
    }
    else {
         indata>>input;
         gt.push_back(input);
         indata>>input;
         snr.push_back(input);
    }
    ++i;
}


Something like that. If you insist on using arrays, you will have to determine the number of inputs first of course.
Thank you!
Wait, I messed up on that one. It should be i%6 not i%11, sorry but it's early in the morning any my brain is a bit messy.
Topic archived. No new replies allowed.