利用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");
}
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇:没有了
