gpt4 book ai didi

c++ - 如何使用boyer_moore_search在内存中搜索char * string?

转载 作者:搜寻专家 更新时间:2023-10-31 00:36:47 26 4
gpt4 key购买 nike

char * pStart = ...;
char * pLast = ...;
std::string pattern("wn3901s");

std::string::const_iterator it = boost::algorithm::boyer_moore_search<>(
???,
???,
pattern.begin(),
pattern.end()
);

我试图在内存中搜索一个大的char* 字符串,pStart 指向它的第一个字符地址; pLast 指向最后一个。

但是,我不想将 char* 字符串转换为 std::string,因为那样的话内存会被复制,这就是我想要的避免。

现在我遇到了为 boyer_moore_search 方法传递前 2 个参数的问题,该方法在那里接受 const_iterator

我应该从 const_iterator 添加一个新的继承类来模拟 char* 字符串吗?能举个例子吗?

谢谢

最佳答案

你可以使用 char * 作为迭代器

char *iterator_ = boost::algorithm::boyer_moore_search(pStart, pLast, pattern.begin(), pattern.end());

An iterator is any object that, pointing to some element in a range of elements (such as an array or a container), has the ability to iterate through the elements of that range using a set of operators (with at least the increment (++) and dereference (*) operators).

The most obvious form of iterator is a pointer.

http://www.cplusplus.com/reference/iterator/

关于c++ - 如何使用boyer_moore_search在内存中搜索char * string?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20933618/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com