是否有 STL 算法可用于像 memmem() 一样搜索缓冲区内的字节序列?
我不知道这是否是好的代码,但是以下代码可以使用std::search http://www.cplusplus.com/reference/algorithm/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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)