c++ - 递减迭代器直到 vector 的 .begin()

标签 c++ vector iterator

我需要从迭代器的某个位置向后读取一个 vector ,并将最多 n1 个值放入字典数组中。

虽然我想创建一个循环并递减迭代器,但由于某些原因我陷入了无限循环。

我认为 while 条件有问题?

//I read all the vSignal vector
while (vSignalIt != vSignal.end()) {

    i = 0;
    vSignalIt2 = vSignalIt;

    //Filling the dictionnary array
    if (vSignalIt != vSignal.begin()) {
        do 
        {
            dictionnary[i] = *vSignalIt2;
            vSignalIt2--;
            i++;
        } while (vSignalIt2 != vSignal.begin() || i < (uint8_t)n1);
    }

    //Do something with the value of dictionnary and increase vSignalIt to advance forward in the vSignal vector

}

最佳答案

改变'||'到'&&'

关于c++ - 递减迭代器直到 vector 的 .begin(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39393182/

相关文章:

C++ std::vector<std::string> 迭代器段错误

r - 如何根据逻辑从数值矩阵生成向量或因子(无 for 循环)

c++ - O(1)内存中的随机序列迭代?

c++ - 为什么 C++ 字符串迭代器不检查错误?

c++ - 当索引不是整数常量表达式时,不要使用数组下标;使用 gsl::at() 代替

c++ - 解密密文时出现InvalidCiphertext异常

c++ - 在 PrintOut OLE 函数中设置事件打印机

matlab - MATLAB 中向量的绝对值

javascript - 在迭代器上使用 map()

c++ - 如何使用 STL 为数据点创建最大和最小堆?