首页 > 其他 > 详细

如何打印调试字符串?

时间:2018-05-26 13:47:47      阅读:212      评论:0      收藏:0      [点我收藏+]
#include <WinBase.h>
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
#include <stdio.h>
#include <wchar.h>
static void dbg(const char *fmt, ...)
{
    //获取时间并减去 8 小时时差
    struct timespec ts;
    timespec_get(&ts, TIME_UTC);
    ts.tv_sec += 28800;

    //格式化时间
    char time_buf[32];
    size_t rc = strftime(time_buf, sizeof time_buf, "[%Y-%m-%d %T", gmtime(&ts.tv_sec));
    int time_lenght = snprintf(time_buf + rc, sizeof time_buf - rc, ".%06ld UTC+8]", ts.tv_nsec / 1000);

    //获取参数列表
    va_list args;
    va_start(args, fmt);

    //打印参数列表
    char message[9216] = { 0 };
    vsnprintf_s(message, 9216, 9216 - 1, fmt, args);

    //组合格式化的时间和参数列表字符串
    char debug[10240] = { 0 };
    sprintf_s(debug, 10240, "%s [debug] %s", time_buf, message);

#ifdef WINBASEAPI
    OutputDebugStringA(debug);
#else
    printf("%s\n", debug);
#endif
}

如何打印调试字符串?

原文:https://www.cnblogs.com/cheungxiongwei/p/9092699.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!