How to get the number of all fields in array?
Because I would like to show an array as in PHP:
Code:Array( 1 => "value", 2 => "value2" )
How to get the number of all fields in array?
Because I would like to show an array as in PHP:
Code:Array( 1 => "value", 2 => "value2" )
In c++.. you'll know the number of elements in an array because:
1) you will have to initially declare the size of a static array
for example: int array[5]; will have 6 elements.
2) if you are using a dynamic array, you can just keep track of the array size each time you resize the array.
int *array;
int size = 50;
array = new int[size];
3) if you are using a vector, just use the size( ) function.
example: int size = array.size( ); //will return the current size of the array and store into an integer variable named, 'size'
Last edited by The Brain; 11-16-2004 at 03:25 PM.
- "Problem Solving C++, The Object of Programming" -Walter Savitch
- "Data Structures and Other Objects using C++" -Walter Savitch
- "Assembly Language for Intel-Based Computers" -Kip Irvine
- "Programming Windows, 5th edition" -Charles Petzold
- "Visual C++ MFC Programming by Example" -John E. Swanke
- "Network Programming Windows" -Jones/Ohlund
- "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
- "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel
> for example: int array[5]; will have 6 elements.
You mean 5 elements