如何为未知的 STL 容器声明迭代器?例如,我想编写一个函数来接收容器并使用迭代器将其全部打印出来:
template <class Container> void print(Container c) {
// how to declare iterator???????
my_iterator = c.begin();
while(my_iterator!=c.end()) {
cout << *my_iterator << endl;
my_iterator++;
}
}