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; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- c# – 重载使用yield return
- Flex:在文本区域中搜索“悬停”在“链接”上
- Oracle WebLogic App Server 11gR1(10.3.6)与Ora
- 速度的刺激:托管 AJAX 能否让 Web 应用程序提速
- ruby-on-rails-3 – 在Rails 3应用程序上测试并发
- postgresql – docker postgres pgadmin本地连接
- ruby-on-rails – Rails,production-env,“对象不
- ruby-on-rails – 在ruby .gemspec文件中,如何指
- swift3 错误处理
- 【cocos2d-x从c++到js】11:JS与C++的交互3——C
热点阅读