memmem() STL 方式?
是否有 STL 算法可用于像 memmem() 一样搜索缓冲区内的字节序列?
Is there an STL algorithm which can be used to search a sequence of bytes inside a buffer like memmem() does?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我不知道这是否是好的代码,但以下代码可以使用
std ::搜索
:I don't know if this is good code, but the following works, using
std::search
:std::search
将查找一个序列在另一个序列中的第一次出现。std::search
will find the first occurrence of one sequence inside another sequence.find
和substr
怎么样?What about
find
andsubstr
?为什么不使用strstr?
没有实现任何算法。您可以实现自己的谓词以与 std::find_if 结合使用,但在我看来,这是过度设计的。
Why not use strstr?
There is no algorithm implemented. You could implement your own predicate to be used in combination with std::find_if, but it is overengineering, IMO.