How can I count the number of characters that are printed as output?

c, c++

Solution

According to the printf man page, printf returns the number of characters printed.

int count = printf("%d", 1000);

If an output error is encountered, a negative value is returned.

Problem

Does anyone know how I can print and count the number of characters that I printed? Say I have a number I am printing via `printf` or `cout`. How could I count the actual number of digits I have printed out?

Original source