How can I access a character of awstring? How can I use theat()method of wide strings in modern C++ software? Can I usefront()andback()methods instd::wstringto access characters?
Modern C++ usesWide StringsandUnicode Stringsto supportworldwide languages.Wide Strings…
How To Define Vectors In Modern C++ On Windows
November 1, 2021
In this post, you’ll get answers to these questions:
What are the Vectors in C++?How can we use std::vector?How can I define vectors for different data types?Can I define structs or other datatypes in std::vector?
By learning how to define vectors in modern C++ on…
How To Use C++ front() And back() Methods Of Vectors
October 20, 2021
In this post, you’ll get answers to these questions:
What are the Vectors in C++?How can I use the front() iterator method on vectors?How can I use the back() iterator method on vectors?Can I get the last member of a vector by using the back() method?How can I access…
Helpers for Generic C++ Code Iterating Over Sequences
December 12, 2020
The iterator library that is part of the C++ Standard Library provides the following helpers for writing generic code:
#include <iterator> // helpers are defined here
template<class Container>
void foo(Container& c)
{
// Generic way to obtain (constant) iterators
auto b = std::begin(c); // (1)
auto cb = std::cbegin(c); // (2)
auto e = std::end(c); //…
Range-for-statement in Modern C++
December 12, 2020
Since C++11 there are elegant way to access each element of a containers (or, more generally, sequences) – so called range-for-statement. The syntaxes are follow:
template<class Container>
void foo(Container& container)
{
for (auto element : container)…
The Move Iterator Adapter in C++
December 6, 2020
The dereference prefix operator * being applied to iterator returns the lvalue reference to the element pointed by the iterator. Therefore, algorithms such as std::copy or std::transform calls copying constructors of processed elements, for example:
#include <algorithm>
#include <list>
#include <string>
#include <vector>
auto deep_copy_to_list(const…
Reverse Iterators in C++
December 6, 2020
By using bidirectional iterator or random access iterator (see Iterator Categories in C++) it’s possible to traverse the sequence in backward direction by using operator -- or by using the special adapter template class std::reverse_iterator. But why to bother with…
Categories of Iterators in C++
December 5, 2020
Conceptually, iterators are consists of five categories:
input iterator is intended to traverse sequences in the forward direction and provides the read access to the pointed sequence element;output iterator is intended to traverse sequences in the forward direction and…
Introduction to C++ Iterators
December 5, 2020
Iterator abstracts the concept of pointer to the sequence in range [begin, end), and thus provides the following basic operations:
dereference to obtain the current element;movement to point the next element;comparison to determine at least the end of sequence.
Iterator to the element of the sequence in range [begin, end) is valid from the moment of initialization and until:
the moment it…