1、find函数
原型:size_t find ( const string& str, size_t pos = 0 ) const;
功能:查找子字符串第一次出现的位置。
参数说明:str为子字符串,pos为初始查找位置。
返回值:找到的话返回第一次出现的位置,否则返回string::npos
2、substr函数
原型:string substr ( size_t pos = 0, size_t n = npos ) const;
功能:获得子字符串。
参数说明:pos为起始位置(默认为0),n为结束位置(默认为npos)
返回值:子字符串
实例
#include<iostream>
#include <thread>
#include <string>
using namespace std;
int main() {
string my_string = "abcdefgssssss";
string result = my_string.substr(3);
std::cout << result << std::endl;
}
打印结果
/home/cai/CLionProjects/study_opencvcc/cmake-build-debug/test2
defgssssss
Process finished with exit code 0
网友评论