美文网首页
c++分割字符串

c++分割字符串

作者: 送分童子笑嘻嘻 | 来源:发表于2019-12-19 09:44 被阅读0次

    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
    

    相关文章

      网友评论

          本文标题:c++分割字符串

          本文链接:https://www.haomeiwen.com/subject/zfxmnctx.html