1

我想在一些 2 个索引之间获取一些数据。例如,我有字符串:“just testing...”,我需要从 2 到 6 的字符串。我应该得到:'st tes'。

什么功能可以为我做到这一点?

4

2 回答 2

3

使用substr

std::string myString = "just testing...";

std::string theSubstring = myString.substr(2, 6);

请注意,第二个参数是子字符串的长度,而不是索引(您的问题有点不清楚,因为从 2 到 6 的子字符串实际上是 'st t',而不是 'st tes')。

于 2010-01-28T18:21:54.730 回答
1

使用substr方法:

std::string theString = "just testing";
std::string theSubstring = theString.substr(2, 4);
于 2010-01-28T18:22:25.650 回答