切割字符串S

函数原型(简化):string substr(const size_type _Off = 0, const size_type _Count = npos){}。第一个参数是切割的起始位置(默认为0),第二个参数是切割字符的数目(默认切割到最后) 

#include<string>
#include<iostream>
using namespace std;

int main() {
    string s = "123abc";
    string t = s.substr(1);  //输出为 23abc。
    cout << t << endl;
    t = s.substr(1, 3);  //输出为 23a。
    cout << t << endl;
    return 0;
}


版权声明:本文为m0_60492395原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。