1

データを配列に保存して再利用しようとしています。データは次の形式で、1964 年から 2013 年のものです。これは単なるスニペットです。

 a     b    c       d        e       f     

1964   9   20.5     8.8       0    37.4     
1964  10   13.6     4.2       5    77.8     
1964  11   11.8     4.7       3    45.5     
1964  12    7.7     0.1      17    65.1     
1965   1    7.3     0.8      14    74.6     
1965   2    6.5     0.1      13     3.3     

これは、これまでのコードで私がどこにいるのかです:

#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;
#include <vector>
#include <string>

struct Weather
{
  int a;
  int b;
  double c;
  double d;
  int e;
  double f;
  double g;
};

int main()
{
  std::vector<Weather> data_weather;
  string line;
  std::ifstream myfile ("weatherdata.txt");
  if (myfile.is_open())
    {
        while ( getline(myfile, line) )
        {

    std::istringstream buffer(line);
    int a_d, b_d, c_d, d_d, e_d, f_d, g_;
    buffer >> a >> b >> c >> d >> e >> f >> g;

    data_weather.push_back(Weather());
    data_weather.back().a = a_d;
    data_weather.back().b = b_d;
    data_weather.back().c = c_d;
    data_weather.back().d = d_d;
    data_weather.back().e = e_d;
    data_weather.back().f = f_d;
    data_weather.back().g = g_d;

    cout << line << endl;

        }
        myfile.close();
    }
    else
        cout << "unable to open file";

        scat::pause("\nPress <ENTER> to end the program.");

    return 0;
}
4

4 に答える 4