共用方式為


array::swap

交換兩個陣列內容。

void swap(array& right);

參數

  • right
    要交換內容的陣列。

備註

成員函式交換在 *this 和 right的控制順序。 它會執行許多工作項目,而且建構函式呼叫比例與 N。

範例

 

// std_tr1__array__array_swap.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 = {4, 5, 6, 7}; 
    c0.swap(c1); 
 
// display swapped contents " 4 5 6 7" 
    for (Myarray::const_iterator it = c0.begin(); 
        it != c0.end(); ++it) 
        std::cout << " " << *it; 
    std::cout << std::endl; 
 
    swap(c0, c1); 
 
// display swapped contents " 0 1 2 3" 
    for (Myarray::const_iterator it = c0.begin(); 
        it != c0.end(); ++it) 
        std::cout << " " << *it; 
    std::cout << std::endl; 
 
    return (0); 
    } 
 
  

需求

標題: <陣列>

命名空間: std

請參閱

參考

<array>

array::operator=