void PRINT_ELEMENTS(const T& coll, const char* optcstr = " ") {
typename T::const_iterator pos;
cout << optcstr;
for (pos = coll.begin(); pos != coll.end(); ++pos) {
cout << *pos <<" ";
}
cout << endl;
}
一个案例实现:
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
template <class T>
void PRINT_ELEMENTS(const T& coll, const char* optcstr = " ") {
typename T::const_iterator pos;
cout << optcstr;
for (pos = coll.begin(); pos != coll.end(); ++pos) {
cout << *pos <<" ";
}
cout << endl;
}
int main()
{
char name1[10];
char name2[10];
cin.get(name1,9,'.');
cin >> name2;
PRINT_ELEMENTS(static_cast&