std ::機能を置き換えます

ヘッダファイルをインクルードする必要があります#include <algorithm>

テンプレート< クラス ForwardIterator、クラス T>
 のボイド置き換える(ForwardIteratorまず、ForwardIterator最後、
                 constの T&OLD_VALUE、constの T&NEW_VALUE)。

実装:

テンプレート< クラス ForwardIterator、クラス T>
 のボイド(ForwardIteratorまず、ForwardIterator最後、交換する
                 のconst T&OLD_VALUE、constの T&NEW_VALUE)
{ 
  しばらく(最初=!{最後の)
     場合 *最初=(OLD_VALUE *最初==)NEW_VALUE。
    ++ 最初; 
  } 
}

参考例:

// アルゴリズム例交換 
する#include <入出力ストリーム>      // はstd :: COUT 
の#include <アルゴリズム>     // はstd ::を交換 
する#include <ベクトル>        // のstd ::ベクトル

INT のmain(){
   int型 myints [] = { 1020303020101020 }。
  std ::ベクトル < 整数 > myvector(myints、myints + 8)。            // 10 20 30 30 20 10 10 20

  std ::置き換える(myvector.begin()、myvector.end()、2099); // 10 99 30 30 99 10 10 99 

  のstd :: coutの << " myvectorは含まれています:" ;
  以下のため(のstd ::ベクトル< int型 ;それ= myvector.end()!++> ::それはmyvector.beginを()=イテレータそれ)
    はstd :: coutの << '  ' << * それ。
  std :: coutの << ' \ nを' ; 

  リターン 0 ; 
}

出力:

画像

おすすめ

転載: www.cnblogs.com/betterwgo/p/10620577.html