从四个给定的无符号字符数组中计算平均数组



假设我总共有四个unsigned char数组,它们像下面这样被添加到一个映射容器中:

std::map<std::string, unsigned char*> UCArray;
UCArray.insert(std::make_pair("A1", new unsigned char[10000]));
UCArray.insert(std::make_pair("A2", new unsigned char[10000]));
UCArray.insert(std::make_pair("A3", new unsigned char[10000]));
UCArray.insert(std::make_pair("A4", new unsigned char[10000]));

我想获得一个基于UCArray的平均值填充的数组,其中所有四个unsigned char缓冲区被初始化并填充有效值。我知道我可以通过两个"for……"来表达我的观点。循环"。请告诉我是否有其他有效的方法来做到这一点。

for(std::map<std::string, unsigned char*>::const_iterator iter = UCArray.begin();
    iter != UCArray.end(); ++iter)
{
   int nAverage =  std::accumulate(
             iter->second, 
             iter->second+10000, 
             0)  / 10000;
}

最新更新