小编Jac*_*nco的帖子

找到两个字符串向量的交集

我有两个字符串向量,并希望找到两者中存在的字符串,用公共元素填充第三个向量.编辑:我已经添加了完整的代码清单与相应的输出,以便事情清楚.

  std::cout << "size " << m_HLTMap->size() << std::endl;

  /// Vector to store the wanted, present and found triggers
  std::vector<std::string> wantedTriggers;
  wantedTriggers.push_back("L2_xe25");
  wantedTriggers.push_back("L2_vtxbeamspot_FSTracks_L2Star_A");
  std::vector<std::string> allTriggers;

  // Push all the trigger names to a vector
  std::map<std::string, int>::iterator itr = m_HLTMap->begin();
  std::map<std::string, int>::iterator itrLast = m_HLTMap->end();
  for(;itr!=itrLast;++itr)
  {
    allTriggers.push_back((*itr).first);
  }; // End itr

  /// Sort the list of trigger names and find the intersection
  /// Build a typdef to make things clearer
  std::vector<std::string>::iterator wFirst = wantedTriggers.begin();
  std::vector<std::string>::iterator wLast = wantedTriggers.end();
  std::vector<std::string>::iterator aFirst …
Run Code Online (Sandbox Code Playgroud)

c++ algorithm vector

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

标签 统计

algorithm ×1

c++ ×1

vector ×1