16.19 write a function to accept a container reference, print the elements in the container, and control the print element loop using the size_type and size members of the container.
16.20 rewrite the function of the previous question and use the iterator returned by begin and end to control the loop.
# Include <iostream> # include <string> # include <vector> # include <list> using namespace STD; Template <typename T> void print1 (const T & V) {auto iter = v. begin (); For (typename T: size_type I = 0; I! = V. size (); ++ I) cout <* ITER ++ <""; cout <Endl;} template <typename T> void print2 (const T & V) {auto iter = v. begin (); While (ITER! = V. end () cout <* ITER ++ <""; cout <Endl;} int main () {vector <int> VEC = {1, 2, 4, 5, 6, ,}; List <int> lst = {,}; print1 (VEC); print2 (LST); Return 0 ;}
Typename identifies static members and types in a template.