Поделиться через


basic_string::basic_string

Создает строку, в которой содержится, инициализированный конкретными символами, или копировать все или часть другой строки (объединения завершенных) строкового объекта или стиля 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
);

Параметры

  • _Ptr
    C# строка символов, которая будет использоваться для инициализации, построенными string. Это значение не может быть пустым указателем.

  • _Al
    Класс распределителя хранилища построенный строкового объекта.

  • _Count
    Число символов для инициализации.

  • _Right
    Строка для инициализации построенный строка.

  • _Roff
    Индекс символа в строке, первые, используемый для инициализации символы для построенный строки.

  • _Ch
    Значение символа, которое должно быть скопировано в построенный строку.

  • _First
    Итератор, const_pointer или const_iterator ввода слишком первый элемент в диапазон источника, который необходимо вставить.

  • _Last
    Итератор, const_pointer или const_iterator ввода слишком положение одного за последним элементом в диапазон источника должен вставляться.

Возвращаемое значение

Ссылка на строковый объект, формируемый конструкторами.

Заметки

Все конструкторы сохраняют basic_string::allocator_type и инициализируют контролируемая последовательность. Объект распределителя аргумент al, если в настоящий момент. Для конструктора копий это right.basic_string::get_allocator(). В противном случае содержит значение Alloc().

Контролируемая последовательность инициализации на копию последовательности операнда определенной оставшимися операндами. Конструктор без последовательности операнда задает начальную контролируемую пустую последовательность. Если InputIterator целочисленного типа в конструкторе шаблона, _F irst, _Last последовательности операнда работает аналогично (size_type)_First, (value_type)_Last.

Пример

// 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;
}

Output

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.

Требования

Заголовок:<string>

Пространство имен: std

См. также

Ссылки

Класс basic_string

<string>

Значения Lvalue и Rvalue

Другие ресурсы

члены basic_string

Члены <string>