[转] 如何使用vector的reserve和resize方法 您所在的位置:网站首页 resize方法 [转] 如何使用vector的reserve和resize方法

[转] 如何使用vector的reserve和resize方法

#[转] 如何使用vector的reserve和resize方法| 来源: 网络整理| 查看: 265

原帖地址:http://blog.csdn.net/linhao19841211_2/article/details/8154805

reserve和resize是vector里两个很重要的方法,有效地使用这两个方法可以减少reallocate memory的次数,提高程序的性能,所以还是有必要去研究一下的,先来看一段简单的代码吧。

stdafx.h

[html] view plain copy // stdafx.h : include file for standard system include files,   // or project specific include files that are used frequently, but   // are changed infrequently   //      #pragma once      #include "targetver.h"      #include    #include             // TODO: reference additional headers your program requires here   #include    #include    #include    using namespace std;  

 test.cpp

[cpp] view plain copy // test.cpp : Defines the entry point for the console application.   //      #include "stdafx.h"      class A   {   public:       A() : m_a(0)       {       }          A(int a) : m_a(a)       {       }          A(const A& a) : m_a(a.m_a)       {       }          ~A()       {       }      private:       int m_a;   };      int _tmain(int argc, _TCHAR* argv[])   {       vector myVec;       myVec.reserve(100);       cout 


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有