关于可变参数(不定参数),以及windows下将进程的cpu,内存统计信息写到日志

本文探讨了在Windows环境下如何利用可变参数进行日志封装,以提高代码封装性和美观性。同时,介绍了如何使用psapi库获取进程CPU和内存使用情况,并将这些统计信息写入日志。在实现过程中,提到了需要安装Windows SDK以及针对VC6.0的兼容性问题,通过设置环境变量和添加依赖项来解决问题。
摘要由CSDN通过智能技术生成

单纯的写日志,没必要使用可变参数,但是不利于封装,代码难看,今天研究了一下可变参数

先查看手册:http://www.cplusplus.com/reference/cstdio/vsprintf/?kw=vsprintf 

function
<cstdio>

vsprintf

int vsprintf (char * s, const char * format, va_list arg );
Write formatted data from variable argument list to string
Composes a string with the same text that would be printed if  format was used on  printf, but using the elements in the variable argument list identified by  arg instead of additional function arguments and storing the resulting content as a  C string in the buffer pointed by  s.

Internally, the function retrieves arguments from the list identified by  arg as if  va_arg was used on it, and thus the state of  arg is likely to be altered by the call.

In any case,  arg should have been initialized by  va_start at some point before the call, and it is expected to be released by  va_end at some point after the call.

Parameters

s
Pointer to a buffer where the resulting C-string is stored.
The buffer should be large enough to contain the resulting string.
format
C string that contains a format string that follows the same specifications as  format in  printf (see  printf for details).
arg
A value identifying a variable arguments list initialized with  va_start.
va_list is a special type defined in 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值