加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – memmem()STL方式?

发布时间:2020-12-16 09:28:49 所属栏目:百科 来源:网络整理
导读:有没有一个STL算法可以用来搜索缓冲区内的字节序列,就像memmem()那样? 解决方法 我不知道这是不是很好的代码,但以下工作,使用 std::search : #include cstdio#include string.h#include algorithmint main(int argc,char **argv){ char *a = argv[0]; char
有没有一个STL算法可以用来搜索缓冲区内的字节序列,就像memmem()那样?

解决方法

我不知道这是不是很好的代码,但以下工作,使用 std::search

#include <cstdio>
#include <string.h>
#include <algorithm>

int main(int argc,char **argv)
{
    char *a = argv[0];
    char *a_end = a + strlen(a);
    char *match = "out";
    char *match_end = match+strlen(match); // If match contained nulls,you would have to know its length.

    char *res = std::search(a,a_end,match,match_end);

    printf("%p %p %pn",a,res);

    return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读