从四个给定的无符号字符数组中计算平均数组
Calculate average array from four given unsigned char arrays
假设我总共有四个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;
}
相关文章:
- 指向指向字符数组的指针数组的指针
- 比较字符数组
- 如何使用Crypto++并为RSA返回可打印的字节/字符数组
- 使用无符号字符数组有效存储内存
- 按字符值访问int数组
- 错误:字符数组的初始值设定项太多
- 对字符数组中的元素执行逐位操作
- C++,在int数组中输入字符串或字符会输出0,而不是ascii或error
- C++ 无法在字符数组中使用 for 循环打印字母模式
- 如何在 C++ 中从文件中读取字符数组(带有一些空格)
- 移动二维数组中的字符
- C++ 传递二维字符数组
- 无法在 C++ 中输入字符数组
- C++ 带结构的数组字符
- 数组字符包含量超出预期
- 读取文件并添加到数组字符
- 如何在Qt中更改或替换数组字符
- 为什么编译器不在参数中传递数组字符 *arr[] 的大小?
- 井字棋数组字符错误
- 分割数组字符