Syntax:
#include <string> string(); string( const string& s ); string( size_type length, Char ch ); string( const Char* str ); string( const Char* str, size_type length ); string( const string& str, size_type index, size_type length ); string( input_iterator start, input_iterator end ); ~string();
The string constructors create a new string containing:
For example,
string str1( 5, 'c' ); string str2( "Now is the time..." ); string str3( str2, 11, 4 ); cout << str1 << endl; cout << str2 << endl; cout << str3 << endl;
displays
ccccc
Now is the time...
time
The string constructors usually run in linear time, except the empty constructor, which runs in constant time.