vector<int> 转换为 int*

来源:互联网 发布:finalcaption字幕软件 编辑:程序博客网 时间:2024/04/28 18:30
// libvtftp.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>#include <vector>void ShowIntArray(int* p, int nSize){if (NULL == p || nSize <= 0){return;}TCHAR szBuff[36];::memset(szBuff, 0, sizeof(szBuff));for (int i = 0; i < nSize; i++){int j = *(p + i);std::cout <<j;memset(szBuff, 0, sizeof(szBuff));std::cout << std::endl;}}int _tmain(int argc, _TCHAR* argv[]){typedef std::vector<int> vtInt;vtInt a;for (int i = 0; i < 10; i++){a.push_back(i);}// 假设不知道vector容器大小int*p = NULL;p = new int[a.size()];for (int i = 0; i < a.size(); i++){p[i] = a[i];}// 调用C的库函数ShowIntArray(p, a.size());delete []p;p = NULL;system("pause");return 0;}

0 0
原创粉丝点击