题
我想获得一些2指标之间的一些数据。 例如,我有字符串:“只是测试......”,我需要从字符串2至6.我应该得到: 'ST TES'。
什么功能,能为我做到这一点?
解决方案
使用substr
:
std::string myString = "just testing...";
std::string theSubstring = myString.substr(2, 6);
注意,第二个参数是长度子串,而不是指数(您的问题是有点不清楚,由于子2至6实际上是“ST T”,而不是“ST TES')。
其他提示
使用 SUBSTR 方法:
std::string theString = "just testing";
std::string theSubstring = theString.substr(2, 4);
不隶属于 StackOverflow