C++用string类写split方法
2015-09-21 11:17
281 查看
void Split(const std::string& s, const std::string& delim, std::vector<std::string>* ret) { size_t last = 0; size_t index = s.find_first_of(delim, last); while (index != std::string::npos) { ret->push_back(s.substr(last, index-last)); last = index + 1; index = s.find_first_of(delim, last); } if (index - last > 0) { ret->push_back(s.substr(last, index - last)); } }
相关文章推荐
- C++的重载运算符
- C++ 实现跨平台的目录遍历
- [leetcode]Two Sum C++ python实现
- 【C语言】gdb调试器入门
- const 用法
- 正斜杠和反斜杠-windows、web、c语言大讨论
- C++ Primer 与“类”有关的注意事项总结
- iOS开发之SQLite--C语言接口规范(四) —— Result Values From A Query
- C语言中的复杂声明和定义,以及如何使用typedef进行简化
- C++静态库与动态库
- Unreal Engine 4 C++自定义事件
- C++ - 头文件(.h)和源文件(.cpp)都应该写些什么
- <C/C++算法> 图论基础算法小结(邻接矩阵实现)
- C++ - .h和.cpp文件的区别
- 使用 VC++访问webservice
- 在C++遇到有些关键字或者函数被弃用的情况
- C语言enum枚举类型详解
- C++中变量的类型
- 黑马程序员----C语言学习笔记之运算符2
- 在C++中如何做出进度条