包装outputdebugstring使其支持变参

 以下是老邓对outputdebugstring的一个包装而已,仅供参考。

void dbg(const char* format, ...)
{
#ifdef qpDEBUG
    char buf[4096];
    char* p = buf;
    va_list ap;
    va_start(ap, format);
    int n = vsnprintf_s(buf, sizeof(buf), _countof(buf), format, ap);
    va_end(ap);

    // buf-3 is room for CR/LF/NUL
    p += (n < 0) ? _countof(buf) - 3 : n;
    while (p > buf && isspace(p[-1]))
        *--p = '\0';

    *p++ = '\r';
    *p++ = '\n';
    *p = '\0';

    OutputDebugStringA(buf);
#endif
}

void dbg(const wchar_t* format, ...)
{
#ifdef qpDEBUG
    wchar_t buf[4096];
    wchar_t* p = buf;
    va_list ap;
    va_start(ap, format);
    int n = _vsnwprintf_s(buf, _countof(buf), format, ap);
    va_end(ap);

    // buf-3 is room for CR/LF/NUL
    p += (n < 0) ? _countof(buf) - 3 : n;
    while (p > buf && iswspace(p[-1]))
        *--p = L'\0';

    *p++ = L'\r';
    *p++ = L'\n';
    *p = L'\0';

    OutputDebugStringW(buf);
#endif
}

void dbg(const string& str)
{
#ifdef qpDEBUG
    dbg(str.c_str());
#endif
}

void dbg(const wstring& str)
{
#ifdef qpDEBUG
    dbg(str.c_str());
#endif
}

void dbg(int i, int line, const char* file)
{
#ifdef qpDEBUG
    if (line != 0)
        dbg("%s, %d : %d", file, line, i);
    else
        dbg("%d", i);
#endif
}

void dbg(void* p, const char* file, int line)
{
#ifdef qpDEBUG
    if (line != 0)
        dbg("%s, %d : %x", file, line, p);
    else
        dbg("%x", p);
#endif
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值