Advantage of STL?

A library of container templates approved by the ANSI committee for inclusion in the standard C++ specification. Provides containers and algorithms that have already been written and are available in what is usually called the Standard Template Library (STL). STL provides implementation of Dynamic arrays. STL provides a set of Template classes used to make C++ programming faster and simpler. The components of STL area) Algorithm b) Container c)Iterator d)Function Object d)Adaptor.

 

What are templates?

Templates are basically used to create generic classes and functions, which operates on diff data types without having to overload the function or create new classes with all the possible datatypes that it is suppose to support.

 

Disadvantage of using Templates?

a) Compile/link time  increases b) pointer manipulation problems(not freeing memory)  c) Efficinecy problem 

 

What is MAP in STL?

Its an Associative container.(ie map, set, multimap and multiset). It provides the ability for fast retrieval of datas based on keys.

 

What is an Vector in STL?

Its an Sequencial Container(ie, vector, deque, list) which organizes a finite set of objects all of same type-in a linear arrangement.

 

What is an Iterator

Pointers themselves are iterators . It decouples algorithm from Container.

 

What is the difference between erase() and remove() of std::list?

Remove() removes elements by value, while erase() uses iterator for the same purpose.

 

What is the difference between vector and array?

Vector is a one-dimensional array.   It's also an STL class while array is a data type.

 

What is the difference between list and vector?

The major difference is the way of element access.

Vector elements may accessed randomly while list elements must be accessed sequentially

Vector uses random access iterator while list support bi-directional iterators

Example :

Vector<String> v; v.push_back(hai”);

for(vector<string>::const_iterator I= v.begin(); I != v.end(); ++I)

 cout<< *I  << endl;

 

Does MFC containers use STL?

They are not.  The MFC containers were written before the STL was addedto VC++.  And there semantics are quite different