memmem()STL方式? [英] memmem() STL way?

查看:161
本文介绍了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?

推荐答案

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

I don't know if this is good code, but the following works, using 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 %p\n", a, a_end, res);

    return 0;
}

这篇关于memmem()STL方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆