Code: |
/* 4.1 - creating a vector from an array */ int arr[5]; /* ... code to set values of arr[0]..arr[4] */ vector<int> vec(arr, arr+sizeof(arr)/sizeof(arr[0])); |
Code: |
/* 5.1 - template instantiation */ #include <vector> #include <string> using namespace std; class Person { public: string firstName; string lastName; }; Person people1[5]; vector<int> numbers(20); /* 20-element integer vector initialised with default int value */ vector<char> characters; /* empty character vector */ vector<string> strings; /* empty string vector */ vector<Person> people2(people1, people1+sizeof(people1)/sizeof(people1[0])); /* vector of class Person, initialised with the contents of the people1 array */ |
output generated using printer-friendly topic mod, All times are GMT + 2 Hours