简体   繁体   English

CString::Mid() 是否有 std::string 等价物?

[英]Is there a std::string equivalent for CString::Mid()?

CString::mid()std::string是否有任何等效函数?

The equivalent would be std::string::substr with the following 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;

And you can use it like:你可以像这样使用它:

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM