c++ - 对 vector 中的增量值

标签 c++ vector iterator constants

我正在尝试迭代一个 vector 对,我需要通过这样做来增加对中的一个元素:

for (std::vector<std::pair<Process *, int> >::const_iterator it = process.begin();   it != process.end(); it++) {
        if (queue.size() == 0)
          break;                                                                                                                                                                                 
        while (queue.size() > 0 && it->second < threadsPerProcess * 2) {
          it->first->send(queue.front());
          queue.pop_front();
          ++it->second; // value i am trying to increment
        }
 }

谁能告诉我我做错了什么?

最佳答案

改变这个:

for (std::vector<std::pair<Process *, int> >::const_iterator it = process.begin();   it != process.end(); it++) {

为此:

for (std::vector<std::pair<Process *, int> >::iterator it = process.begin();   it != process.end(); it++) {

以便您实际修改正在迭代的元素。

关于c++ - 对 vector 中的增量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36813862/

相关文章:

c++ - MSVC : unexpected token '__cdecl' , 预期 'expression'

r - 将数字向量与另一个向量中的值进行比较的最佳方法

math - 数学和编程中的向量之间的区别

r - 在数值向量的每对值之间添加序列

c++ - mingw g++ vector<T>::插入错误

c++ - PySide 中的多线程 Boost Python C++ 代码

c++ - 为什么我的重载转换运算符无法访问私有(private)成员?

c++ - 在 MCA 8000A 中编写 Linux 驱动程序

c++ - 没有模板的运算符重载

java - 使用两个迭代器进行迭代