繁体   English   中英

我们可以使用Iterator替换向量元素的值吗?

[英]Can We Replace value of vector element using Iterator?

迭代器在向量中的实际工作方式。如果我们需要替换向量中的数据元素,可以继续进行迭代器还是需要其他实现方式?

以下是我上面查询的代码

#include <bits/stdc++.h>
using namespace std;
vector <string> v;
vector <string> :: iterator it;
int main()
{
    int t,l,i;
    cin >> t;
    for(i=0;i<t;i++){
        string s;
        cin >> s;
        v.push_back(s);
    }
    string s2="replaceable String";
    //Now I want to change some string at index i in vector v to string s2
    for(it=v.begin();it!=v.end();it++){
        cout << *it << endl;
    }
    return 0;
}

迭代器用于指向向量中的插槽或位置。

std::vector的迭代器遵循Random Interators的概念。

您可以将迭代器分配给向量的开头。

您可以将迭代器分配给std::find的结果。

您可以增加迭代器。

您可以通过取消引用插入器来访问数组中的元素。

你还需要什么?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM