Total members 11890 |It is currently Tue Apr 16, 2024 3:11 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Using Vector in C++
cpp code
#include <iostream>

#include <cassert>
#include <vector>
using namespace std;

int main()
{
int N = 10000; // size of vectors

vector<int> vector1, vector2;

for (int k = 0; k != N; ++k) {
vector<int>::size_type cap = vector1.capacity();
vector1.push_back(k);
if (vector1.capacity() != cap)
cout << "k: " << k << ", new capacity: " << vector1.capacity() << endl;
}

return 0;
}

/*
k: 0, new capacity: 1
k: 1, new capacity: 2
k: 2, new capacity: 4
k: 4, new capacity: 8
k: 8, new capacity: 16
k: 16, new capacity: 32
k: 32, new capacity: 64
k: 64, new capacity: 128
k: 128, new capacity: 256
k: 256, new capacity: 512
k: 512, new capacity: 1024
k: 1024, new capacity: 2048
k: 2048, new capacity: 4096
k: 4096, new capacity: 8192
k: 8192, new capacity: 16384

*/




_________________
Please recommend my post if you found it helpful


Author:
Beginner
User avatar Posts: 95
Have thanks: 2 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : C++ Vector capacity
 vector front     -  
 Iterator on Vector     -  
 Vector class     -  
 count elements in a vector     -  
 Data Structures: Vector     -  
 Write Vector list to File     -  
 Support Vector Machine coding on Matlab...     -  



Topic Tags

C++ Data Structures
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com