C++ - Tips'n Tricks - Using a list of pairs

The container list may accept another container.
For example a pair.

So we are trying to add pairs inside a list. It will become a list of pairs!

In the snippet below, I'm using only one file.
So just compile and execute it to see the result.

C - Character manipulation - Converting a char into an int

We can of course transform a char into an int with the atoi() function.

But what we are going to do now it's to create our own function to transform a string (several char) into a number.

UNIX & GNU/Linux - System calls - Using read()

We are going to use the read() function to read on the standard input from our favorite shell.

So each time you will write something then type ENTER, the text written will be display on the shell.

Let's see this, with this tiny tutorial of the read() function with a C example.

C - Keyword - Using extern

The extern keyword is designed to explicitely tells someone, being watching a variable in a code, that this variable has been firstly declared in another file.

The extern keyword works also with C++.

C++ - Algorithm - Using the for_each() function

An example of how using the for_each() function.

Notice that you can have the same result with an iterator, here an example.

C++ - STL (Standard Template Library) - Using the vector container

The vector container is the most classic STL container.

In the snippet below, I can iterate through the vector, so I use an iterator to erase an element of the vector.
In our case, I removed the number 2 from the container and I added 80 to this place.

Let's see this example of the vector container.

C++ - Standard library - Using the pair container

The pair container cannot be iterated.

So we can use it for example to return a double value at the end of a function.

In the snippet below we are going to use it to change the first and the second value.
This, respectively with the pair.first and pair.second methods:

 

C++ - STL (Standard Template Library) - Using the queue container

We are going to see in this queue tutorial, how to use it.

Let's see it with this first snippet.
In the easy example below, we add 10 elements in the queue before displaying its content.
We have to notice that we cannot iterate through a queue.

UNIX & GNU/Linux - System calls - Using gettimeofday()

The system call function gettimeofday() is a really helpful one.

Indeed, we can retrieve milliseconds of the time.

But in this tutorial, we are going to see how to generate random numbers every millisecond.

Here the code:

C - SDL (Simple Directmedia Layer) - Creating a multicolored window

May you want to create a night club with the SDL library?

It is maybe possible.
With the code below of this tutorial, you can generate a different color every millisecond.

So, why waiting?
Let's dance!

Pages

Subscribe to BadproG.com RSS