【问题标题】:Is there a std::string equivalent for CString::Mid()?CString::Mid() 是否有等效的 std::string?
【发布时间】:2020-06-11 05:15:58
【问题描述】:

std::string 中是否有与CString::mid() 等效的功能?

【问题讨论】:

    标签: c++ c-strings stdstring


    【解决方案1】:

    相当于std::string::substr,具有以下接口:

    basic_string substr( size_type pos = 0, size_type count = npos ) const;
    constexpr basic_string substr( size_type pos = 0, size_type count = npos ) const;
    

    你可以像这样使用它:

    std::string str = "0123456789abcdefghij";
    
    // returns [pos, size())
    std::string sub1 = str.substr(10);
    std::cout << sub1 << '\n';
    
    // returns [pos, pos+count)
    std::string sub2 = str.substr(5, 3);
    

    【讨论】:

      猜你喜欢
      • 2013-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多