Why Boost: format and printf behave differently on the same line of format

The Boost Format document says:

One of its goals is to provide a substitute for printf, which means the format can parse the format string intended for printf, apply it to the given arguments and get the same result as printf.

When I compare the output of boost: format and printf using the same format string, I get different outputs. Online example here

#include <iostream>
#include <boost/format.hpp>

int main()
{
    boost::format f("BoostFormat:%d:%X:%c:%d");

    unsigned char cr =65; //'A'
    int cr2i = int(cr);

    f % cr % cr % cr % cr2i;

    std::cout << f << std::endl;
    printf("Printf:%d:%X:%c:%d",cr,cr,cr,cr2i);
}

Output:

BoostFormat: A:A:A:65

printf: 65:41:A:65

The difference is that I want to display char as an integral type.

Why is there a difference? Is this a mistake or a desire for behavior?

+4
source share
1

.

boost manual , :

printf . / , .

, stdlib-printf char int - vararg. , :

printf("Printf:%d:%X:%c:%d",cr2i,cr2i,cr2i,cr2i);

%.

+4

Source: https://habr.com/ru/post/1616696/


All Articles