Is there a simple way to get the number of characters printed in C++?
问题 printf(...) returns the number of characters output to the console, which I find very helpful in designing certain programs. So, I was wondering if there is a similar feature in C++, since the cout<< is an operator without a return type (at least from what I understand of it). 回答1: You can associate your own streambuf to cout to count the characters. This is the class that wraps it all: class CCountChars { public: CCountChars(ostream &s1) : m_s1(s1), m_buf(s1.rdbuf()), m_s1OrigBuf(s1.rdbuf(&m