小编Jac*_*shi的帖子

在字符串C++中查找子字符串(在"hello"中找到"el")

好的,所以我一直在寻找一种可以帮助我在子字符串中找到字符串的算法.我之前使用的代码来自一个类似的问题,但它没有这样做.

// might not be exposed publicly, but could be
int index_of(string const& haystack, int haystack_pos, string const& needle) {
  // would normally use string const& for all the string parameters in this
  // answer, but I've mostly stuck to the prototype you already have

  // shorter local name, keep parameter name the same for interface clarity
  int& h = haystack_pos;

  // preconditions:
  assert(0 <= h && h <= haystack.length());

  if (needle.empty()) return h;
  if (h == haystack.length()) …
Run Code Online (Sandbox Code Playgroud)

c++ string recursion substring find

2
推荐指数
1
解决办法
3万
查看次数

标签 统计

c++ ×1

find ×1

recursion ×1

string ×1

substring ×1