Skip to content

Latest commit

 

History

History
49 lines (33 loc) · 1.56 KB

Documentation.md

File metadata and controls

49 lines (33 loc) · 1.56 KB

pprintpp Documentation

How to use

It's easy. Just add the library to your include path, and include <pprintpp.hpp>. pprintpp.hpp defined the macro pprintf, which just depends on the original printf.

#include <cstdio>
#include <pprintpp.hpp>

int main()
{
  pprintf("Hello {s}!, {} {} {}\n", "world", 123, 123ull, 1.23);
}

"Advanced" Usage

pprintpp tries to be as printf compatible as possible, but there are some pecularities:

Adding Additional Format Directives

printf historically supports indendation, hex printing of unsigneds, etc. via additional optional format specifiers between % and the actual type format character.

pprintpp accepts these between the {} brackets. Examples:

pprintf("Int with 10 characters indentation: {10}\n", 123);
pprintf("Unsigned long long or whatever in hex notation: {#8x}\n", static_cast<unsigned long long>(0x123));

Printing Strings

It would easily be possible, to transform pprintf("{}", "some string"); to printf("%s", "some string");. For safety reasons, i decided to not automatically print everything as a string, which looks like a character array.

In order to print such a string, please put an "s" between the braces: {s}: pprintf("{s}", "some string");.

Printing Actual { Braces

Braces can be normally printed as before pprintpp, but the opening ones have to be masked in order to tell pprintpp to not interprete these as place holders:

pprintf("These are braces: \\{}.\n");
pprintf("JSON document: \\{ "foo" : "bar", "value" : {} }\n", 123);