1.string();
2.string( const string& s );
3.string( size_type length, constchar& ch );
4.string( const char* str );
5.string( const char* str, size_type length);
6.string( const string& str, size_type index, size_type length);
7.string( input_iterator start, input_iterator end );
翻译:
1.构造一个空string对象
2.拷贝构造给定的string字符串s
3.用字符ch填充长度为length的字符串
4.
用C字符串作构造str
5.用C字符串的前length个字符构造字串
6.用str的第index个字符开始,选取长度为length的字串构造
7.
以区间[beg,end)内的字符构造字符串
实例:
#include "iostream"
#include "string"
#include "iterator"
using namespace std;
int main( void )
{
const char*c_str = "abcdefg";
std::stringstr("123456");
strings(str);
strings_len( c_str , 4 );
strings_index( c_str , 1,3 );
strings_iterator(str.begin(), str.end());
cout<< "string( const char* str) /
string str(\"123456\") "<< str<< endl;
cout<< "string( conststring& s ) /
string s(str) " << s<< endl;
cout<< "string( const char* str,size_typelength ) /
string s_len( c_str , 4 )"<< s_len<< endl;
cout<<"string(conststring& str,size_type index,size_type length)/
string s_start( c_str,1,3 )" <<s_index << endl;
cout<<"string( input_iteratorstart,input_iterator end) /
string s_iter(str.begin(), str.end())"<< s_iter<< endl;
return0;
}
运行结果:
string( const char* str)
stringstr("123456") 123456
string( const string& s)
string s(str) 123456
string( const char* str, size_type length)
string s_len( c_str , 4) abcd
string( const string& str,size_type index,size_typelength )
string s_start( c_str, 1, 3 ) bcd
string(input_iterator start,input_iteratorend)
strings_iter(str.begin(),str.end()) 123456
2.string( const string& s );
3.string( size_type length, constchar& ch );
4.string( const char* str );
5.string( const char* str, size_type length);
6.string( const string& str, size_type index, size_type length);
7.string( input_iterator start, input_iterator end );
- 1.nothing; an empty string,
- 2.a copy of the given string s,
- 3.length copies of ch,
- 4.a duplicate of str (optionally up to lengthcharacters long)
- 5.a substring of str starting at index andlength characters long
- 7.a string of characterss denoted by the start andend iterators
实例:
#include "iostream"
#include "string"
#include "iterator"
using namespace std;
int main( void )
{
}
运行结果:
string( const char* str)
stringstr("123456")
string( const string& s)
string s(str)
string( const char* str, size_type length)
string s_len( c_str , 4)
string( const string& str,size_type index,size_typelength )
string s_start( c_str, 1, 3 )
string(input_iterator start,input_iteratorend)
strings_iter(str.begin(),str.end())