so I'm trying to read in some data from a csv file into my program, but I only want some specific columns. I know there is a lot of stuff online regarding this but I can't seem to fit any of them to my requirements.
Firstly, I have created a struct that takes in Date and Time (class objects) and a Speed value from a file, and store it in Vector template class I have made myself. My main program right now works correctly for a test file like this:
31/12/2013 11:45,55.6
Date and time is read together, and then separated, and it works fine. Now here is the actual file:
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
31/03/2016 09:10,14.6,194,22,0.1,1013.4,1016.9,1017,0,67.2,5,565,22.7,24.1,25.5,26.1,8,20.97
31/03/2016 09:20,14.8,198,30,0.1,1013.4,1016.9,1017,0,68.2,5,574,22.7,24,25.5,26.1,8,20.92
What I want to do is extract details from the WAST column which is date and time, and then the speeds from the S column. I have a generic idea of how to do it i.e: Extract the whole first line into a string and ignore everything other than WAST and S, or something like that. But even then, how am I supposed to get every value under only the columns I want to? Please help.
Main.cpp:
#include <iostream>
#include <string>
#include <fstream>
#include "Date.h"
#include "Time.h"
#include "Vector.h"
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("testinput2.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;
}