#include <iostream>#include <vector>#include <iterator>using namespace std;int main(int argc, char *argv[]) { vector<int> v = {1, 2, 3, 5}; copy(v.begin(), v.end(), ostream_iterator<int>(cout, " ")); return 0;}
#include <iostream>#include <vector>using namespace std;int main(){ std::vector<int> vec; vec.push_back(0); vec.push_back(1); vec.push_back(2); int &a = vec[0]; int &b = vec[1]; int &c = vec[2]; for (int i = 0; i < 15; ++i) { // vec.push_back(i); printf("Address of first element:: %p\n", (void*)&vec[0]); printf("First value:: %d\n", a); printf("Second value:: %d\n", b); printf("Third value:: %d\n\n", c); } return 0;}
Address of first element:: 0x603010First value:: 0Second value:: 1Third value:: 2Address of first element:: 0x603050First value:: 6303776Second value:: 0Third value:: 2Address of first element:: 0x603050First value:: 6303776Second value:: 0Third value:: 2Address of first element:: 0x603050First value:: 6303776Second value:: 0Third value:: 2Address of first element:: 0x603050First value:: 6303776Second value:: 0Third value:: 2Address of first element:: 0x603080First value:: 6303776Second value:: 0Third value:: 2
Address of first element:: 0x8051488First value:: 0Second value:: 1Third value:: 2Address of first element:: 0x80514b8First value:: -1785358955Second value:: -1785358955Third value:: -1785358955Address of first element:: 0x80514b8First value:: -1785358955Second value:: -1785358955Third value:: -1785358955Address of first element:: 0x80514b8First value:: -1785358955Second value:: -1785358955Third value:: -1785358955Address of first element:: 0x80514b8First value:: -1785358955Second value:: -1785358955Third value:: -1785358955Address of first element:: 0x80514f8First value:: -1785358955Second value:: -1785358955Third value:: -1785358955