Most of the C++ programmers are familiar with vector. Vectors are a kind of sequence containers. As such, their elements are ordered following a strict linear sequence.

Vectors have their elements stored in contiguous storage locations. So their elements can only be accessed by iterators and offsets.

 

For example, I have one structure like

 

struct Info

{

      DWORD dwRollNo;

      char szName[65];

};

Also I have one vector like this..

 

typedef vector< Info *> INFO;

 

By using vector::push_back() or vector::push_front(), we can insert data into the structure.. That’s a simple thing.

 

Here we insert some data to the vector.

 

INFO* studentInfo;

for(…….)

{

            studentInfo ->push_back(….);

}

 

How can we iterate through the above structure?

 One way is like this.. J

 

INFO studentInfo;

INFO::iterator sIter;

 

for (sIter = detailsList.begin( ); sIter!= detailsList.end( ); sIter ++ )

      {

            Info* sValues = (Info *)(*sIter);

            MessageBox(sValues ->szName);

      }

 

You’re not free unless you follow your heart!!!

for https://vctipsplusplus.wordpress.com/

BijU

Advertisements