使用stirng的substr函数, 其中第一个参数是起始位置, 第二个参数是子串的长度
#include <iostream>
#include <string>
using namespace std;
int main() {
string a = "20170816";
string b = a.substr(0,4);
string c = a.substr(4,2);
string d = a.substr(6,2);
cout << b << endl << c << endl << d << endl;
}
本文介绍如何使用C++中的std::string成员函数substr从一个字符串中提取子串。通过实例演示了如何设置起始位置及子串长度来获取特定格式的数据。
2万+

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



