Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Is there any equivalent function in std::string for CString::mid()?

like image 236
noggy Avatar asked Sep 06 '25 02:09

noggy


1 Answers

The equivalent would be std::string::substr with the following interface:

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);
like image 112
NutCracker Avatar answered Sep 07 '25 21:09

NutCracker