std::string
中是否有与 CString::mid()
等效的功能?
最佳答案
等价于带有以下接口(interface)的 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);