I like how easy it is to write some variables to console output in C++ using qDebug
from Qt:
int a = b = c = d = e = f = g = 1;
qDebug() << a << b << c << d << e << f << g;
Result:
1 1 1 1 1 1 1
In comparison, using std::cout
would require me to add the spacing and newline manually to get the same result:
std::cout << a << " " << b << " " << c << " " << d << " " << e << " " << f << " " << g << "\n";
While I often use Qt, I sometimes work on projects where adding the Qt framework just to get access to qDebug would be overkill. And although it is not hard to write a new class that behaves similar to qDebug
, I am wondering if any established alternative to std::cout
with similar behavior to qDebug
already exists?
Edit: What I am looking for is ideally an established library (or snippet, but I prefer something existing over rolling my own) that I can always use as my go-to solution when I need something like this. It could be header-only, or a large logging library that is much used and well-tested, or a simple, small snippet. The point is that it should be small and/or standard enough that other collaborators would be okay with including it in a project just for debugging/logging purposes.
Edit 2: To clarify: It would be great to have a solution that both inserts spaces between the variables and newlines for each statement:
myDebug << 1 << 2 << 3;
myDebug << 4 << 5 << 6;
Should return:
1 2 3
4 5 6