Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resizing an array in C++

Status
Not open for further replies.

Greggie

Technical User
Jun 25, 2001
24
AU
I have an array that I want to be dynamic, that is, that can be resized according to the needs of the program. How can I resize the array and preserve its current values?
 
Sounds more like you want to use a linked list OR one of the MFC lists.


Matt
 
You may also try using vector. Ankan.

Please do correct me if I am wrong. s-)
 
also you can use STL vectors what are compatible with much many C++ compillers than MFC.
#include<vector>
#include<algorithm>
using namespace std;
....
int x;
vector<int> vx;
vector<int>::iterator ivx;
vx.push_back(x);
vx.push_back(10);
vx.push_back(20);
x = vx[1];
ivx = find(vx.begin(),vx.end(),10);
if(ivx != vx.end) x = *ivf;
... Ion Filipski
1c.bmp


filipski@excite.com
 
try using calloc

#include <stdio.h>
#include <malloc.h>

void *calloc( size_t num, size_t size );

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top