如何在 C++ 中获取 std::string 的前两个字符
要获取 myString 的前两个字符,像这样使用 myString.substr():
substr_example.cpp
std::string firstTwo = myString.substr(0, 2);substr() 的第一个参数是偏移量(即要跳过多少字符),在此例中为 0,因为我们不想跳过任何字符。
substr() 的第二个参数是要获取的字符数。由于我们想获取两个字符,所以这是 2。
Check out similar posts by category:
C/C++
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow