如题目所示,如何在vector<string>
中查找一个string
类型的字符串,标准库中的find()
对于vector<string>
类型不知道如何使用。 谢谢!
如题目所示,如何在vector<string>
中查找一个string
类型的字符串,标准库中的find()
对于vector<string>
类型不知道如何使用。 谢谢!
这是题主想要的么
#include <bits/stdc++.h>
using namespace std;
int main() {
int N = 5;
vector <string> v;
for(int i = 0;i < N; i++) {
string tmp;
char a[5];
for(int j = 0;j < 3; j++)
a[j] = 'a'+i;
a[3] = '\0';
v.push_back(a);
}
auto idx = find(v.begin(), v.end(), string("bbb")) - v.begin();
cout<<idx<<endl;
return 0;
}
template< class InputIt, class T >
InputIt find( InputIt first, InputIt last, const T& value );
InputIt的first和last是传入的迭代器
3 回答2k 阅读✓ 已解决
2 回答3.9k 阅读✓ 已解决
2 回答3.2k 阅读✓ 已解决
1 回答3.2k 阅读✓ 已解决
1 回答2.7k 阅读✓ 已解决
3 回答3.4k 阅读
1 回答3.3k 阅读