I'd like to define my own printf output conversions:
printf("%T", widget);
For gcc, I can use printf.h
as shown here .
How can I do this for Windows (Visual Studio)?
This is a "bad idea" (tm) - it is much, much easier. more sensible, more portable and more maintainable to write an ordinary function to do the conversion. For example (assuming widget has an id and a name):
void PrintWidget( Widget * w ) {
printf( "widget id %d name %s " , w->id, w->name );
}
与其让printf
进行转换,不如为您的对象提供一个转换为字符串并让printf
正常输出字符串的printf
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.