Need a recommendation on how to proceed with this task...I am starting new in C++ (after taking it in high school 11 years ago it has been forgotten and has changed alot). I have put the code I have below and some sample lines of data...any recommendations on how to load my array of weather observations would be appreciated. You will find that data is separated by a space and line breaks between observations. I only need the first several lines to remain individual and the rest of the observation I want to store as a string 'otherstuff'...is this even possible to do? I was having trouble with the getline working (which I know from reading is a common mistake). Help would be appreciated...
Attached below 1) Code to present 2) Sample Text
#include <iostream>
#include <fstream>
#include <string>
#include<iomanip>
using namespace std; // put standard names into default namespace
//Struct Weather to decode obs in txt file to individual components
struct Weather {
int years;
int months;
int days;
int hours;
int windr;
int windsp;
int gust;
int waveht;
int waveperiod;
string otherstuff();
};
void main() {
string stuff;
int counter = 0;
Weather Later[75000];
/*I have 75000 weather observations to decode and I want the structure to easily check each parameter against limitations I have using If-Then nested in a For-Loop (or While)*/
ifstream DataFile("2007.txt");
while(!DataFile.eof()) {
getline(DataFile, stuff, ' ');
// This is where I want to distribute the paramters to the struct
counter++;
cin.get();
}
DataFile.close();
/*This is where I want the nested If in a For loop to check the array of Structs once I dl all data*/
}
/****DATA FILE VIEWS LIKE THIS***
YYYY MM DD hh WD WSPD GST WVHT DPD APD MWD BAR ATMP WTMP DEWP VIS
1999 01 27 00 235 5.7 6.6 .47 9.09 3.89 131 9999.0 4.3 7.0 -.8 99.0
1999 01 27 01 999 99.0 99.0 99.00 99.00 99.00 999 9999.0 999.0 999.0 999.0 99.0
1999 01 27 02 249 5.7 99.0 .58 3.45 3.87 261 9999.0 5.2 999.0 -.8 99.0
1999 01 27 03 253 6.2 7.1 .59 3.45 3.72 253 9999.0 5.5 7.0 -.6 99.0
1999 01 27 04 999 99.0 99.0 99.00 99.00 99.00 999 9999.0 999.0 999.0 999.0 99.0
1999 01 27 05 254 7.8 9.0 99.00 99.00 99.00 999 9999.0 999.0 7.0 999.0 99.0
1999 01 27 06 999 99.0 99.0 99.00 99.00 99.00 999 9999.0 999.0 999.0 999.0 99.0
1999 01 27 07 999 99.0 99.0 .81 4.35 3.95 214 9999.0 4.7 999.0 .5 99.0
1999 01 27 08 999 99.0 99.0 .78 4.55 4.00 215 9999.0 999.0 7.0 999.0 99.0
1999 01 27 09 263 4.3 5.8 .71 4.17 4.08 217 9999.0 4.7 7.0 999.0 99.0
1999 01 27 10 999 99.0 99.0 99.00 99.00 99.00 999 9999.0 4.5 7.0 .4 99.0
1999 01 27 11 999 99.0 99.0 99.00 99.00 99.00 999 9999.0 999.0 999.0 999.0 99.0
1999 01 27 12 999 99.0 99.0 99.00 99.00 99.00 999 9999.0 999.0 999.0 999.0 99.0
1999 01 27 13 999 99.0 99.0 99.00 99.00 99.00 999 9999.0 999.0 999.0 999.0 99.0
1999 01 27 14 282 4.0 5.1 .58 4.76 4.19 199 9999.0 4.4 7.0 -1.3 99.0
*/