复制以特定位置开头的字符串的一些数量的字符的子字符串。
basic_string<CharType, Traits, Allocator> substr(
size_type _Off = 0,
size_type _Count = npos
) const;
参数
_Off
定位元素的索引。字符串副本的位置,使用默认值 0。_Count
要复制的字符数,则它们。
返回值
为字符串操作数开始元素复制的位置。对象的子字符串的第一个参数指定了。
示例
// basic_string_substr.cpp
// compile with: /EHsc
#include <string>
#include <iostream>
int main( )
{
using namespace std;
string str1 ("Heterological paradoxes are persistent.");
cout << "The original string str1 is: \n " << str1
<< endl << endl;
basic_string <char> str2 = str1.substr ( 6 , 7 );
cout << "The substring str1 copied is: " << str2
<< endl << endl;
basic_string <char> str3 = str1.substr ( );
cout << "The default substring str3 is: \n " << str3
<< "\n which is the entire original string." << endl;
}
要求
标头:< 字符串>
命名空间: std