Exercise 4.28: Write a program to read the standard input and build a vector of ints from values that are read. Allocate an array of the same size as the vector and copy the elements from the vector into the array.
/* C++ Primer 习题 4.28 * By Ceeji */ #include <iostream> #include <vector> using namespace std; typedef vector<int> arr_int; int main() { int value; arr_int a = arr_int(); // 输入元素数据。 while (cin >> value) { a.push_back (value); } int * sz = new int [a.size()]; arr_int::iterator iter = a.begin (); while (iter != a.end ()) { *sz = *(iter++); cout << *sz << endl; } return 0; } |