Home  »  ArticlesTips   »   C++ Format the Fast Formatting Library. Did You Know? Ep 1.

C++ Format the Fast Formatting Library. Did You Know? Ep 1.

There are many libraries out there that do all sorts of things and that includes those like this fast formatting library for C++. The library is C++ Format. This is a library that is designed to be a subtle replacement for the traditional printf and sprintf C language constructs. It is that which we will be taking a peek into in today’s episode of Did you know?

Did You Know There is a Fast Formatting Library for C++ Output?

The answer should be yes if not eventually, yes! C++ Format pronounced cppformat is an open-source formatting library for C++. We know printf can be an unsafe method of printing to the standard output. C++ Format therefore comes in as a worthy alternative to printf and an alternative to IOStreams. Other alternative include loki::SPrintf and boost::format.

Variadic templates feature crom C++11 can be used where supported otherwise variadic functions are emulated by generating a set of lightweight wrappers. Some of the features include functions that perform formatting and writing of the results to a file. You can also leave out the file and write directly to the stdout. String literals can also be formatted similar to Python programming language.

C++ Format comes with a concatenation-based Write API. This provides a fast stateless alternative to IOStreams and functions similarly to std::cout. The library is also type safe and comes with automatic memory management. This helps prevents buffer overflows.

C++ Format can used to compile on Windows, Linux and Mac operating systems running the latest versions of GCC 4.4 and later, and Visual C++ 2010 or later. The usage is simple with the entire library consisting of a single header file and a single source file with no dependencies.

As you go over to Github to get yourself a copy of this library, you can take a look at the following which are good examples on how the C++ Format can be used:

Ref:
http://cppformat.github.io/latest/index.html
http://zverovich.net/2013/09/07/integer-to-string-conversion-in-cplusplus.html

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.

Available under:
Articles, Tips