#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
int main() {
string str = "123456";
cout << str.substr(3, 2);//从下标 3 开始, 截取 2 个字符
cout << str.substr(2);// 截取下标为 2 及其之后的所有字符
return 0;
}
C++ string之substr()
最新推荐文章于 2025-06-19 14:31:40 发布
本文展示了一个使用C++进行字符串操作的例子,具体演示了如何使用substr方法从字符串中截取特定部分。通过两个实例,一是从指定下标开始截取固定长度的字符,二是截取从指定下标到字符串末尾的所有字符。

750

被折叠的 条评论
为什么被折叠?



