Saturday, 26 October 2013

Introduction to STL and Containers


The Standard Template Library (STL) is a software library for the C++ programming language that influenced many parts of the C++ Standard Library. It provides four components called algorithmscontainersfunctional, and iterators.
The STL provides a ready-made set of common classes for C++, such as containers and associative arrays, that can be used with any built-in type and with any user-defined type that supports some elementary operations (such as copying and assignment). STL algorithms are independent of containers, which significantly reduces the complexity of the library.



are a kind of holder objects having a collection of other objects , they are a kind of class templates allowing greater flexibility. This simply means all
the following containers are already defined you just need to include them and start using them .


 array of fixed size , here you can make an array of size 100000 without any problem which will not work with normal array that we are familiar with.
        you need to include array like this

deque - 

double ended queue has dynamic size and can be expanded and contracted on both the ends


list -

 insertion and deletion at any positon takes same time iteration in both directions .

queue and priority queue -

 we have here predefined functions for insertion deletion and accessing an element


vector -

 they are a kind of expandable arrays

note --->

for using the array container class you need a dev c++ compiler . Also you need to do the following :
1. go to Tools -> compiler options
2. in conmpiler tab in the second text area below "Add the following commands when calling linker " write -std=c++11 after whatever is written and press ok


No comments:

Post a Comment


Blogger Widgets