我将从代码开始:
#include <iostream>
#include <vector>
using namespace std;
struct A
{
int color;
A(int p_f) : field(p_f) {}
};
int main ()
{
A la[4] = {A(3),A(5),A(2),A(1)};
std::vector<int> lv = {begin(la).color, end(la).color};//I would like to create vector from specific value from array la
for (std::vector<int>::iterator it = fifth.begin(); it != fifth.end(); ++it) std::cout << ' ' << *it;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
通常我想从数组中的特定值创建一个向量.你可以看到la是一个数组,我想创建不包含整个la数组的向量,但只包含颜色.vector(int)不是vector(A),哪个是vector {3,5,2,1},所以不是A,而只是int颜色.它也可以在C++ 11中使用.谢谢.
例如我有文字:
“约翰起床了。约翰去看电影了。约翰洗手了。”
现在我想找到第一个“约翰”并做一些事情,然后我想去下一个“约翰”并做一些事情,所以我需要使用类似的东西findNext(),它考虑了实际位置,所以它不会从一开始,而是从实际位置。