Thursday, March 10, 2011

Using C Format Code Macros in C++

First, the macros are located in /usr/include/inttypes.h.

If you look at the header file, you'll see that you need to add -D__STDC_FORMAT_MACROS to your compile command.

An example of using them looks like this:

char s[100];
int32_t value = 5;
snprintf(s, sizeof(s), "%"PRIi32, value);
uint64_t andthen = 6;
snprintf(s, sizeof(s), "%"PRIu64, andthen);

No comments:

Post a Comment