阅读背景:

利用vector给动态数组赋值

来源:互联网 
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void main()
{
	//利用vector给动态数组赋值
	vector<int> iv;
	int maxcnt;
	cout << "请输入元素数量:";
	cin >> maxcnt;
	int temp;
	while (cin >>  temp)
	{
	iv.push_back(temp);
	if (iv.size() == maxcnt)
		break;
	}
	int *p = new int[iv.size()];
	for (size_t ix = 0; ix != iv.size(); ++ix)
	{
		*(p + ix) = iv[ix];
		cout << *(p + ix);
	}
	delete[]p;
system("pause");
}
 #include <iostream>
#include <string>
#include 



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: