C ++エクササイズ|テンプレートパンプログラミングの練習(2)

#include <iostreamの> 
する#include <cmath> 
の#include <CStringの> 
する#include < ストリング > 
の#include <iomanip> 
の#include <アルゴリズム> 
の#include <スタック> 
の#include <fstreamの> 
する#include <地図> 
の#include <ベクトル>
 使用して 名前空間はstdを、

テンプレート <型名T>
 ボイド insortout(ベクトル<T> T)
{ 
    TをT1、
    int型のn; 
    cinを >> N;
    
    { 
        CIN >> T1。
        t.push_back(T1)。
    } 
    ソート(t.begin()、t.end())。
    以下のためにint型 i = 0 ; iがn <I ++の
    { 
        COUT << T [i]は<< ENDLと、
    } 
} 

int型のmain()
{ 
    ベクトル < ストリング > S。
    insortout(S); 
    ベクトル < ダブル > V。
    insortout(V); 
    リターン 0 ; 
}

ベクトルテンプレートの適用

おすすめ

転載: www.cnblogs.com/tsj816523/p/11068903.html