
-----------------------------------
Justin_
Tue Aug 15, 2006 12:00 am

Initializing arrays
-----------------------------------
Its been a while since I last coded in c++.  I'm wondering what the best way to create an array is if you don't know its size.  Must you wait till you know its size or?  

I'm basically creating a const unsigned character array to store the hex of a file, incase you wanted to know.  So actually another good question to ask would be what is the best function to grab the length of a binary file?

-----------------------------------
wtd
Tue Aug 15, 2006 12:40 am


-----------------------------------
If you don't know the size you'll need?  Then don't use an array.

Use one of the STL collections classes.

-----------------------------------
Null
Tue Aug 15, 2006 10:26 am


-----------------------------------
Just expanding what wtd said.

You should try to avoid arrays in C++ in general, as much better solutions exist. The common replacement is the std::vector containter, which handles its own memory. Here's an example: 


#include 
#include 

const int SIZE = 10;

template 
void display(const std::vector &vec) {
	//one way of printing a vector: using indexes
	for(int i = 0; i < vec.size(); i++)
		std::cout 