是否有等效于CString :: Mid()的std :: string?

时间:2020-02-27 08:27:58

标签: c++ c-strings stdstring

std::string中有CString::mid()的等效功能吗?

1 个答案:

答案 0 :(得分: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);