<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hridish G</title>
    <description>The latest articles on DEV Community by Hridish G (@hrdxh).</description>
    <link>https://dev.to/hrdxh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3059350%2F7b1bb795-dc67-40d8-9178-96e3c0580ed0.png</url>
      <title>DEV Community: Hridish G</title>
      <link>https://dev.to/hrdxh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hrdxh"/>
    <language>en</language>
    <item>
      <title>🧃 Just Me, C++ &amp; the STL</title>
      <dc:creator>Hridish G</dc:creator>
      <pubDate>Thu, 17 Apr 2025 13:49:07 +0000</pubDate>
      <link>https://dev.to/hrdxh/just-me-c-the-stl-38je</link>
      <guid>https://dev.to/hrdxh/just-me-c-the-stl-38je</guid>
      <description>&lt;p&gt;Hi! I’m 19, I like building stuff, breaking stuff, and most of all—understanding stuff. When I started learning C++, people kept dropping this term “STL” like it was the cheat code to everything.&lt;/p&gt;

&lt;p&gt;At first, I thought STL was something fancy or complex. But guess what? It's just a bunch of tools that make your life easier. And once you get it, it’s like… "Wait, that’s it? I spent 3 hours debugging a custom sort when this already existed?"&lt;/p&gt;

&lt;p&gt;So here’s my no-BS, friendly guide to the Standard Template Library (STL) in C++. If you’re just figuring things out like me — this is for you.&lt;/p&gt;

&lt;p&gt;🌟 What is STL?&lt;br&gt;
STL = Standard Template Library&lt;/p&gt;

&lt;p&gt;Think of it like a really well-organized toolbox. Inside it, you get:&lt;/p&gt;

&lt;p&gt;Containers (like boxes to store stuff: arrays, lists, stacks…)&lt;/p&gt;

&lt;p&gt;Algorithms (functions like sort, reverse, find)&lt;/p&gt;

&lt;p&gt;Iterators (like pointers that help you move through containers)&lt;/p&gt;

&lt;p&gt;Basically, it’s a bunch of pre-written code that you can use without reinventing the wheel every time.&lt;/p&gt;

&lt;p&gt;📦 STL Containers – Where You Store Stuff&lt;br&gt;
Let’s start with containers, because duh — you gotta put stuff somewhere before you do stuff to it.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Vector – The Cooler, Smarter Array
A vector is like a dynamic array that can grow and shrink. Super useful.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;vector&amp;gt;

int main() {
    std::vector&amp;lt;int&amp;gt; nums = {1, 2, 3};

    nums.push_back(4); // adds 4 at the end
    nums.pop_back();   // removes last element

    for(int i : nums) {
        std::cout &amp;lt;&amp;lt; i &amp;lt;&amp;lt; " ";
    }

    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;🧠 Why it's cool: You don’t have to specify the size beforehand. Just vibe and let it grow.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Set – No Duplicates Allowed, Sir
A set stores unique values in sorted order.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;set&amp;gt;

int main() {
    std::set&amp;lt;int&amp;gt; s;

    s.insert(5);
    s.insert(2);
    s.insert(5); // ignored

    for(int x : s) {
        std::cout &amp;lt;&amp;lt; x &amp;lt;&amp;lt; " ";
    }

    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;🧠 Use this when you want only unique values and don’t want to sort manually.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Map – Key-Value Store Like a Mini Dictionary
If you’re from Python-land, this is like a dict.
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;map&amp;gt;

int main() {
    std::map&amp;lt;std::string, int&amp;gt; ages;

    ages["Alice"] = 20;
    ages["Bob"] = 19;

    for(auto pair : ages) {
        std::cout &amp;lt;&amp;lt; pair.first &amp;lt;&amp;lt; " is " &amp;lt;&amp;lt; pair.second &amp;lt;&amp;lt; " years old.\n";
    }

    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;💡 Perfect when you want to associate keys with values.&lt;/p&gt;

&lt;p&gt;⚙️ Algorithms – Do the Work For You&lt;br&gt;
STL also gives you a ton of built-in algorithms that make life easier.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Sort It Like It’s Hot
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;vector&amp;gt;
#include &amp;lt;algorithm&amp;gt;

int main() {
    std::vector&amp;lt;int&amp;gt; nums = {5, 2, 8, 1};

    std::sort(nums.begin(), nums.end());

    for(int i : nums)
        std::cout &amp;lt;&amp;lt; i &amp;lt;&amp;lt; " ";

    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;💡 sort() uses quicksort/intro sort internally and is optimized AF.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Find Stuff Without Writing Loops
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;iostream&amp;gt;
#include &amp;lt;vector&amp;gt;
#include &amp;lt;algorithm&amp;gt;

int main() {
    std::vector&amp;lt;int&amp;gt; nums = {10, 20, 30};

    if(std::find(nums.begin(), nums.end(), 20) != nums.end()) {
        std::cout &amp;lt;&amp;lt; "Found it!";
    } else {
        std::cout &amp;lt;&amp;lt; "Nope.";
    }

    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;🔍 Way better than writing that awkward for loop.&lt;/p&gt;

&lt;p&gt;🔁 Iterators – Fancy Pointers (kinda)&lt;br&gt;
You can think of iterators as your way of saying:&lt;/p&gt;

&lt;p&gt;“Hey, I want to start here and keep going until I say stop.”&lt;/p&gt;

&lt;p&gt;Used a lot in algorithms:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;std::sort(v.begin(), v.end()); // begin() and end() are iterators
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also manually iterate like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for(auto it = v.begin(); it != v.end(); ++it) {
    std::cout &amp;lt;&amp;lt; *it &amp;lt;&amp;lt; " ";
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(But honestly, use range-based for loops unless your college prof insists otherwise lol)&lt;/p&gt;

&lt;p&gt;🛠️ STL In Real Life&lt;br&gt;
Let me be real — I used to manually write sorting functions, brute force loops to check duplicates, etc. And then I found out STL had my back this whole time.&lt;/p&gt;

&lt;p&gt;In contests, interviews, or college assignments — STL is a massive time-saver. Learn it early, thank yourself later.&lt;/p&gt;

&lt;p&gt;🔚 Wrapping Up (TL;DR)&lt;br&gt;
If you scrolled to the end like I sometimes do (no judgment), here’s the gist:&lt;/p&gt;

&lt;p&gt;STL gives you containers (like vector, set, map), algorithms (like sort, find), and iterators to make coding way easier.&lt;/p&gt;

&lt;p&gt;Use #include  and all that good stuff.&lt;/p&gt;

&lt;p&gt;You’re not a lesser dev for using STL — you’re actually smarter for not wasting time.&lt;/p&gt;

&lt;p&gt;🌱 My Personal Take&lt;br&gt;
I’m just starting out — I mess up, I Google a lot, I sometimes forget semicolons 😅&lt;br&gt;
But each time I learn something like STL, it makes me feel a bit more in control.&lt;/p&gt;

&lt;p&gt;If you’re in that same phase — figuring things out, writing spaghetti code, and trying to make sense of it all — I feel you.&lt;/p&gt;

&lt;p&gt;Let’s keep learning. One bug fix at a time.&lt;/p&gt;

&lt;p&gt;✍️ Thanks for reading!&lt;br&gt;
If you liked this post or related to the vibe, feel free to drop a comment or follow. I’ll be writing more of these dev-log style posts.&lt;/p&gt;

&lt;p&gt;Catch you in the next one 🫶&lt;br&gt;
URL: &lt;a href="https://hrdxh.hashnode.dev/a-relaxed-look-at-c-and-the-stl-discovering-the-standard-template-library" rel="noopener noreferrer"&gt;https://hrdxh.hashnode.dev/a-relaxed-look-at-c-and-the-stl-discovering-the-standard-template-library&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
