Export (0) Print
Expand All

array::assign

Replaces all elements.

void assign(const Ty& val);

val

The value to assign.

The member function replaces the sequence controlled by *this with a repetition of N elements of value val.

 

// 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); 
    } 
 
 0 1 2 3
 4 4 4 4

Header: <array>

Namespace: std

Community Additions

ADD
Show:
© 2014 Microsoft