小编use*_*552的帖子

如何从数组中的特定值创建向量?

我将从代码开始:

#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中使用.谢谢.

c++ arrays constructor vector c++11

4
推荐指数
1
解决办法
240
查看次数

在 Python 中是否类似于字符串中的 findNext() 方法?

例如我有文字:

“约翰起床了。约翰去看电影了。约翰洗手了。”

现在我想找到第一个“约翰”并做一些事情,然后我想去下一个“约翰”并做一些事情,所以我需要使用类似的东西findNext(),它考虑了实际位置,所以它不会从一开始,而是从实际位置。

python string parsing find

1
推荐指数
1
解决办法
9186
查看次数

标签 统计

arrays ×1

c++ ×1

c++11 ×1

constructor ×1

find ×1

parsing ×1

python ×1

string ×1

vector ×1