Remarque
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de vous connecter ou de modifier des répertoires.
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de modifier des répertoires.
Construit une chaîne qui est vide, initialisé par les caractères spécifiques, ou est une copie de l'ensemble ou une partie d'une autre chaîne (se terminant par null) d'objet String ou de style C.
basic_string();
explicit basic_string(
const allocator_type& _Al
);
basic_string(
const basic_string& _Right
);
basic_string(
basic_string&& _Right
);
basic_string(
const basic_string& _Right,
size_type _Roff,
size_type _Count = npos
);
basic_string(
const basic_string& _Right,
size_type _Roff,
size_type _Count,
const allocator_type& _Al
);
basic_string(
const value_type *_Ptr,
size_type _Count
);
basic_string(
const value_type *_Ptr,
size_type _Count,
const allocator_type& _Al
);
basic_string(
const value_type *_Ptr
);
basic_string(
const value_type *_Ptr,
const allocator_type& _Al
);
basic_string(
size_type _Count,
value_type _Ch
);
basic_string(
size_type _Count,
value_type _Ch,
const allocator_type& _Al
);
template <class InputIterator>
basic_string(
InputIterator _First,
InputIterator _Last
);
template <class InputIterator>
basic_string(
InputIterator _First,
InputIterator _Last,
const allocator_type& _Al
);
basic_string(
const_pointer _First,
const_pointer _Last
);
basic_string(
const_iterator _First,
const_iterator _Last
);
Paramètres
_Ptr
La C-chaîne dont les caractères doivent être utilisés pour initialiser string est construit.cette valeur ne peut pas être un pointeur null._Al
La classe d'allocateur de stockage pour l'objet chaîne qui est construit._Count
Le nombre de caractères à initialiser._Right
La chaîne pour initialiser la chaîne qui est construite._Roff
L'index d'un caractère dans une chaîne qui est la première à utiliser pour initialiser les valeurs de caractères de la chaîne qui est construite._Ch
La valeur de caractères à copier dans la chaîne qui est construite._First
Un itérateur d'entrée, un const_pointer, ou un const_iterator traitant le premier élément de la plage source à insérer._Last
Un itérateur d'entrée, un const_pointer, ou un const_iterator adressant la position de celle au delà de le dernier élément dans la plage source à insérer.
Valeur de retour
Une référence à l'objet chaîne qui est construit par les constructeurs.
Notes
Tous les constructeurs stockent basic_string::allocator_type et initialisent la séquence contrôlée.L'objet d'allocation est l'argument al, le cas échéant.pour le constructeur de copie, c'est right.basic_string::get_allocator().Sinon, elle a la valeur Alloc().
La séquence contrôlée est initialisée avec une copie de la séquence d'opérande spécifiée par les opérandes restants.un constructeur sans séquence d'opérande spécifie une séquence contrôlée par initiale vide.Si InputIterator est un entier dans un constructeur de modèle, le _First, _Last de séquence opérande se comporte les mêmes qu' (size_type)_First, (value_type)_Last.
Exemple
// basic_string_ctor.cpp
// compile with: /EHsc
#include <string>
#include <iostream>
int main( )
{
using namespace std;
// The first member function initializing with a C-string
const char *cstr1a = "Hello Out There.";
basic_string <char> str1a ( cstr1a , 5);
cout << "The string initialized by C-string cstr1a is: "
<< str1a << "." << endl;
// The second member function initializing with a string
string str2a ( "How Do You Do?" );
basic_string <char> str2b ( str2a , 7 , 7 );
cout << "The string initialized by part of the string cstr2a is: "
<< str2b << "." << endl;
// The third member function initializing a string
// with a number of characters of a specific value
basic_string <char> str3a ( 5, '9' );
cout << "The string initialized by five number 9s is: "
<< str3a << endl;
// The fourth member function creates an empty string
// and string with a specified allocator
basic_string <char> str4a;
string str4b;
basic_string <char> str4c ( str4b.get_allocator( ) );
if (str4c.empty ( ) )
cout << "The string str4c is empty." << endl;
else
cout << "The string str4c is not empty." << endl;
// The fifth member function initializes a string from
// another range of characters
string str5a ( "Hello World" );
basic_string <char> str5b ( str5a.begin ( ) + 5 , str5a.end ( ) );
cout << "The string initialized by another range is: "
<< str5b << "." << endl;
}
Sortie
The string initialized by C-string cstr1a is: Hello.
The string initialized by part of the string cstr2a is: You Do?.
The string initialized by five number 9s is: 99999
The string str4c is empty.
The string initialized by another range is: World.
Configuration requise
en-tête : <string>
l'espace de noms : type