(原創) 如何将array转成std::vector? (使用constructor) (C/C++) (STL)

由于C++兼容于C,为了用C++维护以前用C写的程序,可能会遇到用C写的array,但C++的std::vector远比array好用,所以可能必须将array转成std::vector继续维护,以下的程序demo如何将array转成std::vector。

 1 ExpandedBlockStart.gif ContractedBlock.gif /**/ /* 
 2InBlock.gif(C) OOMusou 2006 http://oomusou.cnblogs.com
 3InBlock.gif
 4InBlock.gifFilename    : ArrayToVectorByConstructor.cpp
 5InBlock.gifCompiler    : Visual C++ 8.0
 6InBlock.gifDescription : Demo how to convert array to vector by vector constructor
 7InBlock.gifRelease     : 11/15/2006 1.0
 8InBlock.gif              12/10/2006 2.0
 9ExpandedBlockEnd.gif*/

10 None.gif#include  < iostream >
11 None.gif#include  < vector >
12 None.gif#include  < algorithm >
13 None.gif
14 None.gif using   namespace  std;
15 None.gif
16 ExpandedBlockStart.gifContractedBlock.gif int  main()  dot.gif {
17InBlock.gif  //const int iaSize = 11;
18ExpandedSubBlockStart.gifContractedSubBlock.gif  int ia[] = dot.gif{011235813215589};
19InBlock.gif
20InBlock.gif  // We specify the address of the first element of 
21InBlock.gif  // the array as 1st argument, and the address of 
22InBlock.gif  // one past the last element as 2nd argument.
23InBlock.gif  vector<int> ivec(ia,ia + sizeof(ia)/sizeof(int));
24InBlock.gif  copy(ivec.begin(), ivec.end(), ostream_iterator<int>(cout, "\n"));
25InBlock.gif
26InBlock.gif  return 0;
27ExpandedBlockEnd.gif}


See Also
(原創) 如何将array转成std::vector? (使用vector.insert) (C/C++) (STL)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值