UGN Security Forums
My ProfileMember DirectoryLogin
Search our ForumsView our FAQView our Site Rules
View our CalendarView our Active TopicsGo to our Main Page

UGN Security Store
 

Network Sites UGN Security, Elite Web Gamers, Back of the Web, EveryDay Helper, VNC Web Design & Development
December
Su M Tu W Th F Sa
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Our Sponsors


Latest Postings
My friend NEEDS your HELP!
by Gizmo
11/26/08 12:21 AM
Useful PHP Functions & Code
by Gizmo
11/13/08 09:25 PM
UBBCode Tags
by Gizmo
11/13/08 09:25 PM
Topic Options
Rate This Topic
#17268 - 04/27/03 05:13 PM Vectors of Objects
HitYouth Offline
Junior Member

Registered: 01/03/03
Posts: 8
Hi,

I was just wondering if anyone knew the correct syntax for creating a vector of Objects and from there, accessing the data members of said objects.

Thanks

Top
Our Sponsors
Sponsor Our Sponsors

Sponsor Advertisements help keep UGN Security Online.



Support UGN Security by Purchasing our Sponsors Products.
Top  
#17269 - 04/27/03 05:46 PM Re: Vectors of Objects
pergesu Offline
Stoner Thugsta

Registered: 03/14/02
Posts: 1134
Loc: Pimpin the Colorizzle
Are you talking about STL vectors? An STL vector is just like any other template class, so you can use whatever data type you want with it. Here's a little example program:
Code:
#include <iostream.h>
#include <vector.h>

int main()
{
        // Create a vector of integers
        vector<int> v(10);

        // Fill it up with stuff
        for(int i = 0; i < 10; i++)
                v[i] = i;

        // Display some data from the vector
        cout<<"Max size of vector: " <<v.max_size() <<endl;
        cout<<"Actual size of vector: " <<v.size() <<endl <<endl;

        // Traverse it with an iterator
        vector<int>::iterator iter = v.begin();
        while(iter != v.end())
        {
                // Access the element
                cout<< *iter++ <<" ";
        }

        cout<<endl;

        return 0;
}
Output of the program on my OS X machine:
Code:
bash-2.05a$ ./vector 
Max size of vector: 1073741823
Actual size of vector: 10

0 1 2 3 4 5 6 7 8 9 
bash-2.05a$ 
Since it's STL, all you need to do is change vector to vector and change the assignment loop.

Top
#17270 - 04/28/03 06:39 PM Re: Vectors of Objects
HitYouth Offline
Junior Member

Registered: 01/03/03
Posts: 8
Many thanks! How does the assignment method change when trying to create a vector of objects from within an instantiation of an object? for example a vector of employees instantiated within an employee database.

Do I need to utilise the push_back() function because I seem to be having difficulties in utilizing the standard array style subscript method?

Top
#17271 - 04/28/03 06:42 PM Re: Vectors of Objects
HitYouth Offline
Junior Member

Registered: 01/03/03
Posts: 8
Nevermind figured it out.. Thanks anyway for your help!

Top



Featured Member
Registered: 02/24/08
Posts: 12
Forum Stats
6889 Members
44 Forums
11026 Topics
45805 Posts

Max Online: 677 @ 06/30/07 10:06 PM
Top Posters
Gizmo 6958
UGN Security 4076
§intå× 3252
IceMyst 1449
SilentRage 1273
Ice 1146
pergesu 1134
Infinite 1039
jonconley 954
Girlie 903
Newest Members
lucky vin, prEttyNDistress, AndrewKlilly, border, f4k3m3
6889 Registered Users
Who's Online
0 registered (), 15 Guests and 8 Spiders online.
Key: Admin, Global Mod, Mod
Latest News
Update Humpday - Sept 26, 2008
by Gizmo
11/28/08 03:39 AM
Happy Holidays!
by Gizmo
11/27/08 09:09 AM
New Mailing
by Gizmo
11/24/08 01:30 PM
A special update...
by Gizmo
11/24/08 01:10 PM
Required Reading Update...
by Gizmo
11/07/08 11:36 AM


Donate
  Get Firefox!
Get FireFox!