c++通用算法-fill

#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;

template<typename T>
void print(const T& t){
    typename T::const_iterator iter;
    for(iter=t.begin();iter!=t.end();++iter){
        cout << *iter << endl;
    }
}

int main()
{
    vector<string> v1(4);
    fill(v1.begin(),v1.end(),"h");
    print(v1);
    vector<string> v2;
    fill_n(back_inserter(v2),7,"bye");
    print(v2);
}

h
h
h
h
bye
bye
bye
bye
bye
bye
bye

你可能感兴趣的:(C++,c,算法,C#)