如何计算作为输出打印的字符数?
问题描述:
有谁知道我如何打印和计数我打印的字符数?
Does anyone know how I can print and count the number of characters that I printed?
说我有一个我正在通过 printf
或 cout
。
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?
答
根据 printf man page ,printf返回打印的字符数。
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.