C++ substr
函数文档:http://www.cplusplus.com/reference/string/string/substr/
/*
substr(size_t pos = 0,size_t len = npos) 子字符串是从字符位置pos开始并跨越len字符(或直到字符串结尾,以先到者为准)的对象部分。
*/
eg:
1 #include<bits/stdc++.h> 2 using namespace std; 3 4 int main() { 5 string str = "ABCDEFGHIJKLMN"; 6 string str_1 = str.substr(0); //从参数的位置开始一直读取到字符串结束 ABCDEFGHIJKLMN 7 string str_2 = str.substr(1,4); //从位置1开始读取长度为4的字符串 BCDE 8 size_t pos = str.find("EF"); 9 string str_3 = str.substr(pos); //EFGHIJKLMN 10 11 cout<<"str_1: "<<str_1<<endl; 12 cout<<"str_2: "<<str_2<<endl; 13 cout<<"str_3: "<<str_3<<endl; 14 return 0; 15 }