Tag: examples
C++11 Smart Pointer – Part 1: shared_ptr Tutorial and Examples
In this article we will discuss a smart pointer implementation provide by c++11 i.e. shared_ptr. What is std::shared_ptr<> ? shared_ptr is a kind of Smart Pointer class provided by c++11, that is smart enough to automatically delete the associated pointer when its not used anywhere. Thus helps us to completely remove the problem of memory leaks …
C++11 Smart Pointer – Part 1: shared_ptr Tutorial and ExamplesRead More
C++ : Map Tutorial Part 1: Usage Detail with examples
In this article we see how & why to use std::map in c++. std::map Introduction std::map is an associative container that store elements in key-value pair. Advertisements Benefits of using std::map : It stores only unique keys and that too in sorted order based on its assigned sorting criteria. As keys are in sorted order …
C++ : Map Tutorial Part 1: Usage Detail with examplesRead More
std::for_each Tutorial : Usage Details with Examples
The std::for_each() algorithm allows us to iterate over a given range of elements and perform operations over them.When to use std::for_each() ? Whenever you are iterating over the elements in a array or in a container and performing some different opeartions over them like accessing, modifying etc. Although you can achieve the same by typing …
std::for_each Tutorial : Usage Details with ExamplesRead More
std::bind – Tutorial and Examples
In this article we will see how to use std::bind and when to use. std::bind std::bind is a Standard Function Objects that acts as a Functional Adaptor i.e. it takes a function as input and returns a new function Object as an output with with one or more of the arguments of passed function bound …
C++11 ‘auto’ Tutorial and Examples
In this article we will learn how to use auto variable in C++11. auto is introduces in C++11. With auto we can declare a variable without specifying its type. Its type will be deduced by the data to which its initializing i.e. // Storing a int inside a auto variable auto var_1 = 5; // …
Compiling C++ with Debug Symbols – gdb debugger Tutorial & Examples
In this article we will discuss how to build a C++ / C code in debug mode and how to start the debugging using gdb. Compile Code with Debug Symbols To debug a C or C++ application with gdb, it should be built in debug mode. So that debug symbols can be loaded and used …
Compiling C++ with Debug Symbols – gdb debugger Tutorial & ExamplesRead More
Breakpoints and Backtrace traversal – gdb debugger Tutorial & Examples
In this article we will discuss how to use breakpoints in gdb and check backtrace etc. How to add breakpoints in gdb Breakpoints can be added only at “gdb” prompt i.e. (gdb) To add a breakpoint in running application just press the “Ctrl-C” command to get the “gdb prompt back. Otherwise you can also add …
Breakpoints and Backtrace traversal – gdb debugger Tutorial & ExamplesRead More
Conditional Breakpoints and watchpoints | gdb debugger Tutorial and examples
Conditional Breakpoints Adding a simple breakpoint at a line will stop the running programming whenever that line of code is hit. But this might not be the requirement every time. Suppose we want to add a kind of breakpoint on a line that will get hit only when a condition is met, not always. Let’s …
Conditional Breakpoints and watchpoints | gdb debugger Tutorial and examplesRead More
std::initializer_list Tutorial & Examples | C++11
std::initializer_list<T> is introduced in C++11 to make initialization uniform in C++. Before C++11 it was easy to initialize an array with with default elements like, Advertisements // Initializing array with default values int arr[]= {1,2,3,4,5}; But there was no way no to initialize other containers like vector, list and map etc. For example, there was no …
C++11 – Variadic Template Function | Tutorial & Examples
Variadic Template is introduced in C++11. Variadic Template allows a function to take variable number of arguments of any type. Let’s understand by an example. Advertisements Suppose we want to create a function log() that accepts variable number of arguments of any type and prints them on console i.e. log(1,4.3, “Hello”); log(‘a’, “test”, 78L, 5); class Student; Student …
C++11 – Variadic Template Function | Tutorial & ExamplesRead More