0

テスト中の次のデータがあります。

2011-01-03      2116    
2011-01-03      2120    
2011-01-04      2116    
2011-01-04      2115

および次のコード:

std::map<std::string, std::vector<double> >::iterator tk = test.begin();
std::vector<double>tmp;

std::copy(tk->second.begin(), tk->second.end(), std::back_inserter(tmp));

上記のコードtmpには以下が含まれます。

2116
2120
2116
2115

tk->secondただし、各日付の平均を に挿入したいと思いtmpます。back_inserter をループに書き込む必要がありますか?

4

1 に答える 1

1
for(auto it = test.begin(); it != test.end(); it++)
{
  double sum = 0.0;
  int count = 0;
  for(auto it2 = it->second.begin(); it2 != it->second.end(); it2++, count++)
  { 
    sum += *it2;
  }
  tmp.push_back(sum / count);
}
于 2012-05-05T16:26:29.937 に答える