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;
}

题外话:我帮你整理了包括 AI 写作、绘画、视频(自媒体制作)零门槛 AI 课程 + 国内可直接顺畅使用的软件。想让自己快速用上 AI 工具来降本增效,辅助工作和生活?限时报名

当前页阅读量为: