共用方式為


array::assign

取代所有項目。

void assign(const Ty& val);

參數

  • val
    要指派的數值。

備註

成員函式的 val值之 N 項目的迴圈取代順序由 *this 。

範例

 

// std_tr1__array__array_assign.cpp 
// compile with: /EHsc 
#include <array> 
#include <iostream> 
 
typedef std::array<int, 4> Myarray; 
int main() 
    { 
    Myarray c0 = {0, 1, 2, 3}; 
 
// display contents " 0 1 2 3" 
    for (Myarray::const_iterator it = c0.begin(); 
        it != c0.end(); ++it) 
        std::cout << " " << *it; 
    std::cout << std::endl; 
 
    Myarray c1; 
    c1.assign(4); 
 
// display contents " 4 4 4 4" 
    for (Myarray::const_iterator it = c1.begin(); 
        it != c1.end(); ++it) 
        std::cout << " " << *it; 
    std::cout << std::endl; 
 
    return (0); 
    } 
 
  

需求

標題: <陣列>

命名空間: std

請參閱

參考

<array>

array 類別 (STL)

array::operator=