I am writing a function which prints out the contents of a vector of unknown contents (it's only assumed that std::cout works for them). The function is as follows:
#include <iostream>#include <vector>#include <string>#include <iterator>using namespace std;template<class T> void printvec(vector<T>& vec){ // The following line is the part that doesn't work std::vector<T>::size_type vecsz=vec.size(); if vecsz < 1 throw domain_error("Cannot print contents of an empty vector"); std::string s = typeid(vec[0]).name(); int width=cout.width(); unsigned int count=0; cout << "Printing contents of vector of type " << s << std::endl; for (vector<T>::const_iterator iter = vec.begin(); iter != vec.end(); iter++) { cout << setw(2) << count << "\t" << *iter << endl; count++; } cout.width(width);}