C++中substr函数的用法
来源:互联网 发布:自动统计数字表格软件 编辑:程序博客网 时间:2024/06/11 03:12
substr用法
basic_string substr( size_type pos = 0, size_type count = npos ) const;
Returns a substring [pos, pos+count). If the requested substring extends past the end of the string, or if count == npos, the returned substring is [pos, size()).
Parameters
pos - position of the first character to includecount - length of the substring
Return value
String containing the substring [pos, pos+count).
Exceptions
std::out_of_range if pos > size()
Complexity
Linear in count
#include <string>#include <iostream>using namespace std;int main(){ string a = "0123456789abcdefghij"; // count is npos, returns [pos, size()) //从位置十个开始取到末尾 string sub1 = a.substr(10); cout << sub1 << '\n'; //abcdefghij // 从位置5开始取,取三个 string sub2 = a.substr(5, 3); cout << sub2 << '\n'; //567 // 取最后三个 string sub4 = a.substr(a.size()-3, 50); cout << sub4 << '\n'; //hij try { // pos is out of bounds, throws //当所取位置超出了字符串长度,将抛出异常 string sub5 = a.substr(a.size()+3, 50); cout << sub5 << '\n'; } catch(const std::out_of_range& e) { cout << "pos exceeds string size\n"; }}
阅读全文
0 0
- oracle中substr函数的用法
- oracle中substr函数的用法
- oracle中substr函数的用法
- oracle中substr函数的用法
- oracle中substr函数的用法
- oracle中substr函数的用法
- C++中substr函数的用法
- oracle中substr函数的用法
- oracle中substr函数的用法
- oracle中substr函数的用法
- oracle中substr函数的用法
- C++中substr函数的用法
- C++中substr函数的用法
- C++中substr函数的用法
- C++中substr函数的用法
- C++中substr函数的用法
- C++中substr函数的用法
- C++中substr函数的用法
- IjkMediaPlayer.reset()耗时的一个解决方案
- Others3_淘宝客与淘宝(天猫)购物返利
- Java虚拟机基本结构
- ToolBar 侧滑箭头修改 导航菜单 三条横线 的方法
- Struts2框架学习系列(一)
- C++中substr函数的用法
- 实现自动化测试,首先不是一个技术问题
- Chilkat.Email.ActiveX.v7.9.8-BEAN\
- my97DatePicker中ie为undefined等错误解决
- 不想34被裁退_好好学学大数据吧
- ES6总结--Symbol、Set 和 Map 、Iterator、Class
- POI导入工具类+ layer弹窗 实例
- 变量定义法 True/False 全屏窗口
- ES6总结--Proxy、Reflect