char_traits::assign

分配一个字符值到另一个文件或者到元素的大小字符串的。

static void assign(
   char_type& _CharTo, 
   const char_type& _CharFrom 
);
static char_type *assign(
   char_type* _StrTo, 
   size_t _Num, 
   char_type _CharFrom 
);

参数

  • **_**CharFrom
    值将分配的字符。

  • _CharTo
    将被赋予字符值的元素。

  • _StrTo
    初始组件将分配字符的字符串或字符数组值。

  • _Num
    赋值元素的数目。

返回值

第二个成员函数返回指向第一个 _Num字符串,元素赋予 _CharFrom值。

示例

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

int main( ) 
{
   using namespace std;

   // The first member function assigning 
   // one character value to another character
   char ChTo = 't';
   const char ChFrom = 'f';
   cout << "The initial characters ( ChTo , ChFrom ) are: ( "
        << ChTo << " , " << ChFrom << " )." << endl;
   char_traits<char>::assign ( ChTo , ChFrom );
   cout << "After assigning, the characters ( ChTo , ChFrom ) are: ( "
        << ChTo << " , " << ChFrom << " )." << endl << endl;

   // The second member function assigning 
   // character values to initial part of a string
   char_traits<char>::char_type s1[] = "abcd-1234-abcd";
   char_traits<char>::char_type* result1;
   cout << "The target string s1 is: " << s1 << endl;
   result1 = char_traits<char>::assign ( s1 , 4 , 'f' );
   cout << "The result1 = assign ( s1 , 4 , 'f' ) is: "
        << result1 << endl;
}
  
  
  

要求

标头: <string>

命名空间: std

请参见

参考

char_traits Struct