I am doing competitive programming in C++ from quite some time now . But I do not use any features and benefits that C++ provides over C . I would like to learn C++ to become a good programmer . I think there is STL library for C++ but I am not sure. Please help me how to learn C++ and STL.
- Include < bits/stdc++.h >
- Use namespace std
- For sorting array a, use sort(a,a+100);
- Use C++ reference website to look up the the containers like pair and map.
There are multiple sources where you can learn STL from. Google stl tutorials and you’ll get a thousand tutorials. Have a look at the first few and choose one. Stick with it.
i’d reccomend doing tha chapter 16 “The Standard Template Library” on this website http://www.learncpp.com/
Download a cheat sheet on STL, it’ll give you all the functions that are available in the STL. Go though the cplusplus.com link given by yash_15 in the comments (of the question).
Once you’ve gone through a full tutorial (or half, if you’re lazy like me ), look at people’s submissions and look at what STL related functions they use and start using them.
If you’re coming from C background, i’d suggest going through some C++ tutorial just to get an idea what is there in C++.
In terms of competitive programming, there’s not much difference as you don’t use classes/constructors etc when solving a problem. Although if you’re using malloc to declare memory, then stop using that and use int *i = new int;
TL;DR: Google and learn
Best reference i have found is http://www.sgi.com/tech/stl/
where you can find all stl functions at one place explain with proper examples.
Hope i help you!
STL library is surely there.
For what bits/stdc++.h is used .
For sorting I think algorithm library also provide a simlar function .
For what purpose STL is used .
Also it would be very helpful if you could provide reference to learn it .
bits/stdc++.h is a complete header file.
If you have seen some experts writing a whole page of includes, then all those, and probably even more, get included in your code.
Right from iostream, stdio to iomanip, math to list,queue,map,vector,algorithm etc.
This file is like an includer file.
One example : you might have learnt bit about stacks, queues, etc then you would have observed that push(),pop(),etc are needed to use these concepts.
In STL, you just declare a stack, and an empty stack is ready for you. You can use it simply like a.push_back(5) to add 5 to the stack!
The standard reference site is www.cplusplus.com/reference/stl
Is there a good book on STL and also is there a need for a book ?