#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →
⚡ FREE · 39 SNIPPETS

C++ STL Cheat Sheet: Containers and Algorithms for Coding Rounds

The STL calls competitive programmers and interview candidates use most.

  • 📦 Containers
  • 🧮 Algorithms
  • ⏱️ Complexities

How to use the C++ STL Cheat Sheet

  1. 1. Search or browseType a word like the function or task you need, or pick a section.
  2. 2. CopyEach snippet has its own Copy button, so you can paste it straight into your editor.
  3. 3. DownloadSave the whole C++ STL cheat sheet as plain text or Markdown for offline revision.

What's in it

It's designed for coding interviews and competitive programming, where knowing the right container saves the most time. The 39 snippets are organised into 11 sections: vector, string, pair & tuple, stack / queue, priority_queue, set / map, unordered, algorithm, iterators, complexity, fast I/O.

Example

Search "heap" and you'll find both priority_queue<int>, a max-heap, and the min-heap form with greater<int>, plus the (distance, node) pair version used in Dijkstra's algorithm. The algorithm section shows the remove-duplicates idiom: sort, then v.erase(unique(v.begin(), v.end()), v.end()).

Tips for using it

  • Learn the complexity line by heart; choosing map versus unordered_map is a common interview discussion.
  • Use accumulate with 0LL when sums can exceed the int range.

A quick look, one snippet per section

  • vector: vector<int> v = {3, 1, 2}; v.push_back(4); (dynamic array; amortised O(1) push_back)
  • string: s.substr(pos, len), s.find("ab"), s += "x"; (substring, search, append)
  • pair & tuple: pair<int, string> p = {1, "a"}; p.first; (two values together)
  • stack / queue: stack<int> st; st.push(1); st.top(); st.pop(); (lIFO)
  • priority_queue: priority_queue<int> pq; (max-heap: top() is the largest)
  • set / map: set<int> s; s.insert(5); s.count(5); (sorted unique keys, O(log n))
  • unordered: unordered_map<int, int> cnt; cnt[x]++; (hash map, average O(1))
  • algorithm: sort(v.begin(), v.end()); (sort ascending, O(n log n))
  • iterators: for (auto& x : v) x *= 2; (range-for by reference to modify)

Search the box above for the rest of the C++ STL snippets, or download the full sheet.

Frequently asked questions

Which C++ standard?

C++17; structured bindings need it.

Is this for competitive programming?

Yes, and for interviews. It includes the fast I/O lines.

Is the C++ STL cheat sheet free?

Yes. You can search, read and copy every snippet in the C++ STL cheat sheet without signing up. The first time you download it, we ask once for your name and WhatsApp number; after that downloads and every other Uncodemy tool open straight away.

More free tools

See all free tools