boost::algorithm::contains

让人想犯罪 __ 提交于 2019-12-20 03:06:13

问题


I looked at the template definition and the parameters appear to want iterators across a range and a predicate. I passed in a vector.begin(), ...end(), and a std::string predicate but still get many compile time errors related a host of boost library items. Can I see a clear example of the use of boost::algorithm::contains please?


回答1:


It's fairly simple, I guess you are passing iterators when you should be passing containers.

  std::string s = "fishing"; 
  std::cout << boost::algorithm::contains(s, "is") << std::endl; 
  std::vector<int> v {1,2,3,5,7,2,7,4,5,8};
  std::vector<int> v2 {5,7,2,7,4};
  std::vector<int> v3 {5,7,2,7,3};
  std::cout << boost::algorithm::contains(v, v2) << std::endl;
  std::cout << boost::algorithm::contains(v, v3) << std::endl;


来源:https://stackoverflow.com/questions/15640770/boostalgorithmcontains

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!