Partager via


basic_string::basic_string

Construit une chaîne qui est vide, initialisé par les caractères spécifique, ou est une copie de l'ensemble ou une partie d'une autre chaîne (se terminant par le caractère null) de l'objet String ou du style de l'Assistant De 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
    l'c interface C (chaîne dont les caractères doivent être utilisés pour initialiser string qui est construit. Cette valeur ne peut pas être un pointeur null.

  • _Al
    La classe d'allocateur de stockage pour l'objet de chaîne qui est construit.

  • _Count
    Le nombre de caractères à initialiser.

  • _Right
    La chaîne d'initialisation de la chaîne en cours de élaboration.

  • _Roff
    L'index d'un caractère d'une chaîne qui est la première à utiliser pour initialiser les valeurs de caractère de la chaîne en cours de élaboration.

  • _Ch
    La valeur de caractère à copier dans la chaîne en cours de élaboration.

  • _First
    Un itérateur d'entrée, une const_pointer, ou un const_iterator adressage le premier élément dans la plage source à insérer.

  • _Last
    Un itérateur d'entrée, une const_pointer, ou un const_iterator adressage la position de celles au delà de le dernier élément dans la plage source à insérer.

Valeur de retour

Une référence à l'objet de chaîne qui est créé par les constructeurs.

Notes

Tous les constructeurs d'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 sauvegarde, il s'agit right.basic_string::get_allocator(). Sinon, elle a la valeur Alloc().

La séquence contrôlée est initialisée une copie de la séquence d'opérandes spécifiés 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 entier dans un constructeur de modèle, le _First, _Last de séquence d'opérandes adopte le même comportement 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 : <chaîne>

Espace de noms : std

Voir aussi

Référence

basic_string, classe

<string>

Lvalues et Rvalues

Autres ressources

membres basic_string

<string> membres