Sintaxe:
#include <string> string(); string( const string& s ); string( size_type length, charT ch ); string( const charT* str ); string( const charT* str, size_type length ); string( const string& str, size_type index, size_type length ); string( input_iterator start, input_iterator end ); ~string();
Os construtores de strings criam uma nova string que contém:
Por exemplo,
string str1( 5, 'c' ); string str2( "Now is the time..." ); string str3( str2, 11, 4 ); cout << str1 << endl; cout << str2 << endl; cout << str3 << endl;
mostra
ccccc
Now is the time...
time
Os construtores de strings normalmente correm em tempo linear, excepto o construtor vazio, que corre em tempo constante.