传递格式化的参数给另外一个函数
来源:互联网 发布:淘宝个人退款率怎么看 编辑:程序博客网 时间:2024/06/06 01:38
传递格式化的参数给另外一个函数
// ValistToFunction.cpp : Defines the entry point for the console application.
//
//功能: 传递格式化的参数给另外一个函数
#include "stdafx.h"
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <crtdbg.h>
#include <tchar.h>
#define G_INT_MSG_BUF_SIZE (int)2048
int MyPrintf(TCHAR * szFormat);
int MyPrintfV(TCHAR * szFormat, ...);
int main(int argc, char* argv[])
{
MyPrintfV(_T("[%s] 整理: %d/%d/%d %d:%d"),
"传递格式化的参数给另外一个函数",
2010, 06, 06, 16, 28);
printf("END/n");
getchar();
return 0;
}
/// 字符串格式化时, 依赖定长Buffer不好
/// 见本文目录 <<计算变长字符串入参的最大长度>>
int MyPrintfV(TCHAR * szFormat, ...)
{//入参为格式化的参数列表
va_list args;
va_start(args, szFormat);
PTCHAR pBufMsg = new TCHAR[G_INT_MSG_BUF_SIZE];
_ASSERT(pBufMsg);
memset(pBufMsg, 0, G_INT_MSG_BUF_SIZE);
int nRc = 0;
nRc = _vsntprintf(pBufMsg, G_INT_MSG_BUF_SIZE, szFormat, args);
_ASSERT(G_INT_MSG_BUF_SIZE > nRc);
va_end(args);
MyPrintf(pBufMsg);
delete pBufMsg;
pBufMsg = NULL;
return S_OK;
}
int MyPrintf(TCHAR * szFormat)
{//入参为单一字符串
//这里是打印, 换成别的任务, 就是命令行分析, 执行命令行制定的任务
printf("%s/n", szFormat);
return S_OK;
}
<2010_1219>
得到函数列表中的每个参数, 这里假设每个参数都是串, 如果是别的类型,也当串来解析,然后强转一下.
传可变参数列表给函数, 适用于用户调用函数,这样方便。
在函数内部如果需要把参数列表,再传给内部函数之前,把参数先解析出来保存好,
效率比再把参数列表复制一份传给内部函数的方法效率高.
<2013_0812>
计算变长字符串入参的最大长度
std::wstring StringFormatV(wchar_t * szFormat, ...){//入参为格式化的参数列表 size_t nStrLen = 0; wchar_t * pBufMsg = NULL; std::wstring strRc; va_list args; va_start(args, szFormat); nStrLen = _vsntprintf(NULL, 0, szFormat, args); pBufMsg = new wchar_t[nStrLen + 1]; _ASSERT(pBufMsg); ::ZeroMemory(pBufMsg, (nStrLen + 1) * sizeof(wchar_t)); nStrLen = _vsntprintf(pBufMsg, nStrLen, szFormat, args); va_end(args); strRc = pBufMsg; delete []pBufMsg; pBufMsg = NULL; return strRc;}
- 传递格式化的参数给另外一个函数
- 函数指针当做参数传递给另外一个函数
- 传递参数给函数
- 传递给main函数的三个参数
- CreateThread给线程函数传递的参数
- 用函数作为另外一个函数的参数
- 一种比较好的结构体用于从一个函数传递参数到另外一个函数(对于支持C99的编译器)
- 将整个结构体作为一个参数传递给函数
- Flink传递参数给函数
- 从jsp 接收另外一个jsp的参数并且把这个参数赋值给js 文件;
- 启动另外的APP及传递参数
- [Unity&NGUI&对象]怎么把按钮自身 的 对象 传递给另外一个脚本对象
- 数组名作为函数的参数传递给函数
- 从一个页面传递参数到另外一个页面?
- 利用Irame传递大容量数据给另外一个页面
- 给replace()传递一个函数
- 如何给window.setInterval的函数传递参数
- 如何给window.setInterval的函数传递参数
- 重新安装ubuntu10.04 LTC 有之前的备份文件
- wine sourceinsight3
- gstreamer学习总结二
- ubuntu桌面特效
- ubuntu安装src.rpm包
- 传递格式化的参数给另外一个函数
- ubunutu 安装鼠标手势
- asp.net中 浮动广告不滚动解决方法
- hdparm硬盘测试
- virtual box 启动不了,说是kernel driver 没有安装
- 显示开机信息
- Ubuntu下安装Oracle10g
- Ubuntu系统中evince打开中文PDF乱码的解决方法详解
- 帝国CMS问题汇总。