I have a csv file with several columns and rows. It is quite large, so for testing purpose I have a test file like this:
Code:
WAST,DP,Dta,Dts,EV,QFE,QFF,QNH,RF,RH,S,SR,ST1,ST2,ST3,ST4,Sx,T
31/03/2016 09:00,14.6,175,17,0,1013.4,1016.9,1017,0,68.2,6,512,22.7,24.1,25.5,26.1,8,20.74
What I need to do, is read the date and time from column 1 called 'WAST', and the float values from the column 'S'. So far, I've created a main program that reads from a test file that looks like this:
Code:
31/03/2016 09:00,14.6
Main program:
Code:
using namespace std;
typedef struct {
Date d;
Time t;
float speed;
}WindLogType;
int main()
{
Date dTest;
Time tTest;
float speedtest = 52.5;
Vector<WindLogType> windlog;
ifstream infile("testinput.csv");
if(!infile){
cout << "File not found.";
return -1;
};
WindLogType windlog2;
//int i = 0;
while(!infile.eof()){
infile >> windlog2.d >> windlog2.t >> windlog2.speed;
windlog.add(windlog2);
}
for(int i = 0; i < windlog.size(); i++){
cout << windlog[i].d << " " << windlog[i].t << " Speed: " << windlog[i].speed << endl;
}
infile.close();
return 0;
}
My Date and Time classes use getline to get the correct delimiters and successfully separate the Date and Time from one line, so that seems okay. This program works fine with the second test file. Now how am I supposed to make it so that I read in only the two columns that I want?