C++中substr函数用法 Xieyuw 2020-03-27 杂谈 话不多说直接上模板:substr(start, length),length可填可不填,start必填即返回一个从指定位置开始并具有指定长度的子字符串,字符串中第一个字符的索引为0.123456789#include<bits/stdc++.h>using namespace std;int main() { string str = "hello, world"; string str1 = str.substr(0,5); cout << str1 << endl; return 0;} 结果为hello. updated at Mar 28, 2020 C++ Previous LeetCode--两数之和 hash-table Next 学习笔记 杂谈