Compartilhar via


basic_string::Operator =

Atribuir novos valores de caracteres ao conteúdo de uma cadeia de caracteres.

basic_string<CharType, Traits, Allocator>& operator=(
   value_type _Ch
);
basic_string<CharType, Traits, Allocator>& operator=(
   const value_type* _Ptr
);
basic_string<CharType, Traits, Allocator>& operator=(
   const basic_string<CharType, Traits, Allocator>& _Right
);
basic_string<CharType, Traits, Allocator>& operator=(
   const basic_string<CharType, Traits, Allocator>&& _Right
);

Parâmetros

  • _Ch
    O valor de caracteres a ser atribuído.

  • _Ptr
    Um ponteiro para os caracteres de C -- cadeia de caracteres a ser atribuído à cadeia de caracteres de destino.

  • _Right
    A cadeia de caracteres de origem cujos caracteres devem ser atribuído à cadeia de caracteres de destino.

Valor de retorno

Uma referência ao objeto de cadeia de caracteres que está sendo atribuído novos caracteres pela função de membro.

Comentários

As cadeias de caracteres podem ser atribuídas novos valores de caracteres.O novo valor pode ser uma cadeia de caracteres e C -- cadeia de caracteres ou um único caractere.operator= pode ser usado se o novo valor pode ser descrito por um único parâmetro, se não a função de membro atribuir, que tem mais parâmetros, pode ser usada para especificar que a parte da cadeia de caracteres deve ser atribuído a uma cadeia de caracteres de destino.

Exemplo

// basic_string_op_assign.cpp
// compile with: /EHsc
#include <string>
#include <iostream>

int main( ) 
{
   using namespace std;

   // The first member function assigning a
   // character of a certain value to a string
   string str1a ( "Hello " );
   str1a = '0';
   cout << "The string str1 assigned with the zero character is: " 
        << str1a << endl << endl;

   // The second member function assigning the
   // characters of a C-string to a string
   string  str1b;
   const char *cstr1b = "Out There";
   cout << "The C-string cstr1b is: " << cstr1b <<  "." << endl;
   str1b = cstr1b;
   cout << "Assigning the C-string cstr1a to string str1 gives: " 
        << str1b << "." << endl << endl;

   // The third member function assigning the characters
   // from one string to another string in two equivalent
   // ways, comparing the assign and operator =
   string str1c ( "Hello" ), str2c ( "Wide" ), str3c ( "World" );
   cout << "The original string str1 is: " << str1c << "." << endl;
   cout << "The string str2c is: " << str2c << "." << endl;
   str1c.assign ( str2c );
   cout << "The string str1 newly assigned with string str2c is: " 
        << str1c << "." << endl;
   cout << "The string str3c is: " << str3c << "." << endl;
   str1c = str3c;
   cout << "The string str1 reassigned with string str3c is: " 
        << str1c << "." << endl << endl;
}
  
  
  
  
  
  
  

Requisitos

Cabeçalho: <string>

namespace: STD

Consulte também

Referência

basic_string Class