So you know C++. Now it’s time to learn the Standard Library.
With a lot of attention focused on newer object-oriented languages like Python, you might not think C++ is used for much any more.
Wrong!
Developed by Bjarne Stroustrup at Bell Labs in 1979, C++ is the foundation for a lot of technology. Windows and Mac OS are at least partially written in C++, and so are many of the desktop apps that run on them. JavaScript runs on an engine written in C++.
Programming languages like Python may be steadily rising in popularity, but C++ is faster than any of them. C++ is very close to the hardware level, making it the best programming language for making hardware run faster.
For big companies like Google and Facebook, just a 10% increase in server performance is a big savings in electricity alone. These companies (no matter what the new, popular object-oriented programming language they use) continue to hire C++ programmers to optimize their back ends, and solve scaling issues.
Yep, knowing C++ could land you a job at Google or Facebook.
C++ Standard Library: A definition.
The C++ Standard Library is a reference to help you at every step of your projects related to system programming.
Even if you’re proficient in core C++, understanding the Standard Library will make you a valuable programmer. It allows you to:
- Simplify your code. You don’t need to go out of your way to create new classes and functions that require a lot of extra code.
- Write cleaner, faster code. Even advanced programmers can make simple mistakes when writing functions. Using the Standard Library guarantees your code will run proficiently.
- Avoid maintenance problems. Sticking to the Standard Library makes testing a lot less stressful. If something you write yourself gets ingrained into the entirety of your code and you find a bug, it’s going to take a lot longer to go through your non-standardized code.
The code in the Standard Library is tested by hundreds of thousands of people and gets subjected to more testing and scrutiny than anything you’d implement yourself.
The Standard Library was developed by the greatest minds in C++ over the past few decades. You are guaranteed good performance, no bugs, and solutions that have been tested and re-tested for decades.
Go with the tried-and-true.
What’s in the C++ Standard Library:
The C++ Standard Library can be categorized into 3 components: containers, iterators, and algorithms.
The containers store collections of other objects, and replicate structures used over and over again in programming (arrays, queues, stacks, etc.). The algorithms can be used on ranges of elements. And the iterators are like the glue that binds the containers and algorithms — they’re used to move forward, backward, or to an arbitrary position in the container.
For the detail-obsessed, here’s an extensive list of items in the C++ Standard Library:
- Concepts: These provide a foundation for equational reasoning in programs.
- Utilities: General purpose utilities for program control, dynamic memory management, numeric limits, error handling, and more.
- Strings: Functions to handle wide and multibyte strings, and determine the type contained in character data.
- Containers: Containers for arrays, vectors, and lists. Associative containers. Stack and queue container adaptors.
- Algorithms: Algorithms that operate on containers, plus predefined execution policies for parallel versions of the algorithms.
- Iterators: Definitions for six kinds of iterators, as well as iterator traits, adaptors, and utility functions.
- Numerics: Common math functions, classes for representing complex numbers and arrays, random number generators, rational arithmetic and more.
- Input/Output: Forward declarations of all classes in the input/output library. Assorted input/output class templates.
- Localization: Localization support for character classification and string collation, numeric, monetary, date/time formatting and parsing, and message retrieval.
- Regular Expressions: Classes, algorithms and iterators to support regular expression processing.
- Atomic Operations: Components for fine-grained atomic operations, which allow for lockless concurrent programming.
- Thread Support: Class and supporting functions for threads, mutual exclusion primitives, primitives for asynchronous computations, and thread-waiting conditions.
- File System: Supporting functions for performing operations on file systems and their components (like paths, regular files, and directories).
- Experimental Libraries: Extra additions to the library, including extensions for parallelism and concurrency
Learn the C++ Standard Library at your own pace.
After looking through that list, you can probably already imagine all the ways you could save time and energy in C++. This only scratches the surface.
Master the C++ Standard Library, and you will be a more sought-after C++ programmer. Period.
If we’ve got your attention, you’ll be interested in our latest course on Educative.
C++ Standard Library: Including C++14 and C++17 is an interactive course that walks you through all the most sought-after functions and classes used by C++ developers worldwide.
This course is designed for C++ 17, the most recent revision of C++. While you learn the Standard Library, this course will get you up to speed on the updates and additions made in this revision.
Each lesson features over 100 in-browser code snippets, so you can get a comprehensive understanding of how the library works in a real C++ environment. As always, there’s nothing to install or configure.
This course was created by Rainer Grimm, C++ expert, author, and technology consultant.
Prerequisites? We recommend having an intermediate knowledge of C++ 14, and be able to understand templates and data structures.
Get started today — check out our free preview lessons and see the amazing collection of insights this course has to offer.
Good luck in your C++ journey! If you have any questions or feedback, we’d love to hear from you. Leave us a comment and we’ll be in touch.
Originally published at blog.educative.io on October 30, 2018.