Format string with spaces
pI'm trying to make an elegant logging system in C++. I'm currently using
codeprintf()/code, although codecout/code can also be an option./p pWhat I
want to achieve is something like this/p precodeconsole_log( ClassName,
funcName, Message. ); /code/pre pMy current code for this is simply:/p
precodestatic void console_log( const std::string amp; className, const
std::string amp; funcName, const std::string amp; message ) { printf( %s :
%s : %s\n, className.c_str(), funcName.c_str(), message.c_str() ); }
/code/pre pIt prints nicely, like this/p precode// For example:
console_log( MenuPanel, selectedThisButton, Something happened. );
console_log( MenuPanel, selectedAnotherButton, Another thing happened. );
// Output: MenuPanel : selectedThisButton : Something happened. MenuPanel
: selectedAnotherButton : Another thing happened. /code/pre pHowever, I
want it to be printed in a table-like manner, where all columns are
aligned properly. For example:/p precodeMenuPanel : selectedThisButton :
Something happened. MenuPanel : selectedAnotherButton : Another thing
happened. /code/pre pHow do I make it so that the first and second columns
have the exact same width/number of characters, with additional spaces if
necessary? It doesn't need to be dynamic. Something like setting a column
to 16 characters will do./p pI don't wish to use any third-party libs for
something as simple as this, though. And if possible, no codeboost/code./p
No comments:
Post a Comment