View Single Post
Old 09-07-2006, 02:51 PM   #3 (permalink)
thejeremy
 
True Techie

Join Date: May 2006

Location: Chicago IL

Posts: 104

thejeremy

Send a message via AIM to thejeremy
Default

Make sure you include the <vector> header file (as jaeusm said).

One vector constructor consists of the following,

vector<type> yourArray(x, y);

where "type" is the type of variable that your vector will hold (int, string, etc.), and the initial vector will hold x copies of the value y. For instance, if I used the constructor

vector<int> myArray(10, 0);

myArray would initially be composed of 10 slots that all hold the value 0.

To tack on an additional value at the end of the vector, use the function call push_back.

Here is a code snippet:

vector<string> sentence(3, "hello");
sentence.push_back("world");

The result of sentence is now ["hello", "hello", "hello", "world"]
Of course, for this example, you'd have to include the header file <string> but I'm assuming you already know that
__________________
CPU: AMD Athlon 64 X2 5200+ Windsor, 2.6 GHz
RAM: CORSAIR XMS2 2GB 240-Pin DDR2
VIDCARD: EVGA PCI-Express x16 GeForce 7900GS 256MB
MOBO: ASUS M2N-SLI Deluxe AM2
HDD: Seagate Barracuda 320GB 7200 RPM SATA

my blog: http://jspot.gotdns.com
thejeremy is offline