You are not logged in. Please login at www.codechef.com to post your questions!

×

Learn C++ and STL

3
1

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.

asked 28 Jun '14, 17:52

the65bit's gravatar image

4★the65bit
1.1k101328
accept rate: 13%

edited 29 Jun '14, 01:31

1

STL library is surely there.

(28 Jun '14, 17:58) yash_155★

For what purpose STL is used . Also it would be very helpful if you could provide reference to learn it .

(28 Jun '14, 18:02) the65bit4★
1

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

(28 Jun '14, 18:47) yash_155★

Is there a good book on STL and also is there a need for a book ?

(02 Jul '14, 19:25) the65bit4★

  1. Include < bits/stdc++.h >
  2. Use namespace std
  3. For sorting array a[100], use sort(a,a+100);
  4. Use C++ reference website to look up the the containers like pair and map.
link

answered 28 Jun '14, 17:57

yash_15's gravatar image

5★yash_15
5181716
accept rate: 2%

Thanks . For what bits/stdc++.h is used . For sorting I think algorithm library also provide a simlar function .

(28 Jun '14, 18:01) the65bit4★
2

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.

(28 Jun '14, 18:41) yash_155★

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 :P ), 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

Happy coding!!

link

answered 29 Jun '14, 05:03

tacoder's gravatar image

3★tacoder
5174615
accept rate: 18%

edited 29 Jun '14, 05:04

Thanks @tacoder

(29 Jun '14, 13:48) the65bit4★

topcoder also lists a nice collection of tutorial for stl link1 & link2

link

answered 29 Jun '14, 15:03

bug2312's gravatar image

3★bug2312
31626
accept rate: 12%

Thanks @bug2312

(29 Jun '14, 20:57) the65bit4★

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! Cheers :)

link

answered 29 Jun '14, 15:51

tech_boy's gravatar image

2★tech_boy
1.2k41931
accept rate: 7%

Thanks @tech_boy

(29 Jun '14, 20:57) the65bit4★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,901
×1,470
×277
×86
×41

question asked: 28 Jun '14, 17:52

question was seen: 8,201 times

last updated: 02 Jul '14, 19:25