zoukankan      html  css  js  c++  java
  • 如何打印调试字符串?

    #include <Windows.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
    ", debug);
    #endif
    }
    
  • 相关阅读:
    Android_AyscnTask
    Android_handler
    Android_网络操作
    Android_网络基础
    Android_Fragment
    Android_activity 生命周期
    Android-Dialog
    android_menu
    Android-约束布局
    andorid_相对布局小练习
  • 原文地址:https://www.cnblogs.com/cheungxiongwei/p/9092699.html
Copyright © 2011-2022 走看看