Stream manipulators in C++

July 7, 2017

In C++ language, output streams are a nice way to display information in console. There are some caveats we can talk about - like bufferization, statefulness - but it is not the goal of this article.

Streams have a cool feature to format output (and input) called manipulators. Some of them:

  • flush / endl
  • oct / dec / hex
  • boolalpha / noboolalpha
  • setw() / setfill()

An interesting question is: can we add our owns manipulators? Yes we can! And this is the purpose of this post.

C++ quizzes

February 3, 2017

I found on reddit a very interesting post on C++ quizzes.

I did not know that such things exist, so it was an interesting discover. Now, I can test myself on this vast subject!

The ultimate environment switcher: direnv

February 2, 2017

I usually change a lot of workspaces during my workday. Generally, I have to load or unload different environments: python virtualenv, ruby gems, node modules…

It’s not very convenient to call the right executable or to change PATH variable (or others) when I switch projects.

Finally, I found an incredible tool for this task : direnv.

Create a full path in C++(17)

January 19, 2017

Sometimes, you must create a path in an application. The main function to use on Posix is mkdir, but it is limited to one directory.

When you want a full path like ./users/romain/tests/test1, but you do not know which parts exist, I have a function for this.

Pretty output formatting in C++11

January 19, 2017

Let’s use a new C++11 feature: user-defined literal.

Thanks to this one, you could now declare new type from a string or a number. For example "2012-10-30"_date can create a new Date object with these information.

But we could use this feature to other useful things, like format a nice output.

C++11 decltype in real conditions

January 18, 2017

Today, I would like to talk about the usage of decltype specifier. Appeared in C++11, this new keyword “returns” the type of a variable or an expression. It is similar to auto keyword but not in all situations.

Call the right executable on *nix

January 12, 2017

One of several problems that occurs when you develop scripts is the selection of the right executable, for example usually with python, you can have three executables: python2, python3 and python (which points to one of previous). The problem happens when you have to run your script:

  • by using executable name on command line python ./my_script.py
  • or with a shebang #!/usr/bin/python

A new start

December 16, 2016

Hello everyone,

In this new year 2017, I am opening this blog! I would talk about various subjects: programming, cinema, readings… In fact, everything that comes to my mind.