Sintassi:
#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();
I costruttori della class string creano un nuovo oggeto di tipo string contenente:
Ad esempio, il seguente codice:
string str1( 5, 'c' ); string str2( "Now is the time..." ); string str3( str2, 11, 4 ); cout << str1 << endl; cout << str2 << endl; cout << str3 << endl;
Produrra' il seguente output:
ccccc Now is the time... time
Tutti i costruttori della classe string hanno tempo di esecuzione lineare, salvo il costruttore di default, il quale ha tempo di esecuzione costante.