C++ string类型的split字符串分割函数
2015-09-26 10:56
567 查看
std::vector<std::string> split(const std::string& s, const std::string& delim) { std::vector<std::string> elems; size_t pos = 0; size_t len = s.length(); size_t delim_len = delim.length(); if (delim_len == 0) return elems; while (pos < len) { int find_pos = s.find(delim, pos); if (find_pos < 0) { elems.push_back(s.substr(pos, len - pos)); break; } elems.push_back(s.substr(pos, find_pos - pos)); pos = find_pos + delim_len; } return elems; }
相关文章推荐
- C++ Primer Plus第六版 第十一章 编程练习答案
- C++的几种强制类型转换
- C++ 虚函数表解析
- C/C++笔试准备(1)
- C语言中 .h文件和.c文件的区别
- C语言复习day2
- c的free和c++的delete的区别
- C语言里面 sizeof 的使用
- c/c++程序调试
- C++中的头文件和源文件
- C语言复习day1
- 技术面试(C++)
- C++学习篇——构造函数与析构函数
- C++ 的构造/析构/赋值/拷贝函数比较
- C++拷贝构造函数详解
- eclipse 配置c++开发环境
- C++ | STL 概述
- C++ | 段错误
- c++设计模式----迭代器模式iterator
- 链表的多项式加法链表的多项式加法