C++筆記:習題4.28

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.

#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;
}
当前页阅读量为: