I completed a intro to C++ course this past fall and I am currently working on an assignment where I have been given the option to use a programing language instead of excel to complete the assignment for my micro-meteorology course. Unfortunately in my C++ course I did not write any programs utilizing text files with multiple rows and columns. The following is an excerpt of the text file I am working with:
The data file includes data for the entire year. I would greatly appreciate anyone's advice on how I can safely extract a whole column at a time and store into an array of the concerned variable in order to preform basic calculations. I feel confident that once I have created the arrays I am comfortable with writing the code to perform the calculations and output the results to a text file.
#include <iostream>
...
ifstream f( "my input file.txt" );
If the data file has exactly that format, you can just skip one line with: f.ignore( numeric_limits<streamsize>::max(), '\n' );
then just loop over each row:
1 2 3 4 5 6
unsigned year, month, day;
double discharge, precipitation;
while (f) {
f >> year >> month >> day >> discharge >> precipitation;
// (store the data however you like here)
}