关于函数wsprintf().

summer_more_more_tea 2008-11-23 04:45:31
请问函数wsprintf()怎么用,和printf()用法相同吗?
麻烦看下下面这段代码,sysmetrics是一个结构的数组,结构有三个字段Index, szDesc 和 szLabel。我希望输出三列,前两列左对齐,第三列右对齐。按我的理解wsprintf()与printf()输出格式应该是相同的,那么把高亮的那两句去掉也应正确输出,但是,注释掉这两句之后,第三列好像变为中间对齐(不管怎么说吧,总之不是右对齐),把sprintf()中第二个参数改为%-5d输出的第三列为左对齐,这和我想的结果是一样的(和printf()相同)。
请问这是怎么个问题呢?谢过先。

for( i = 0; i < NUMLINES; i++ ){
SetTextAlign( hdc, TA_LEFT );
TextOut( hdc, 0, cyChar * i, sysmetrics[ i ].szLabel, lstrlen( sysmetrics[ i ].szLabel ) );
TextOut( hdc, 22 * cxCaps, cyChar * i, sysmetrics[ i ].szDesc, lstrlen( sysmetrics[ i ].szDesc ) );
SetTextAlign( hdc, TA_RIGHT );
TextOut( hdc, 22 * cxCaps + 40 * cxChar, cyChar * i, szBuffer, wsprintf( szBuffer, "%5d", GetSystemMetrics( sysmetrics[ i ].Index ) ) );
}
...全文
329 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
icefox97 2008-11-25
  • 打赏
  • 举报
回复
printf();在控制台程序里用于向屏幕上输出数据(" "里面是格式化字符串,逗号后面是对应的要输出的内容)。
sprintf/wpringf();两个是差不多的东西,都将(" "里的格式化字符串,所对应的数据)写入一个char 类型的buf中。
hellward 2008-11-25
  • 打赏
  • 举报
回复
wsprintf
The wsprintf function formats and stores a series of characters and values in a buffer. Any arguments are converted and copied to the output buffer according to the corresponding format specification in the format string. The function appends a terminating null character to the characters it writes, but the return value does not include the terminating null character in its character count.

int wsprintf(
LPTSTR lpOut, // pointer to buffer for output
LPCTSTR lpFmt, // pointer to format-control string
... // optional arguments
);

就呆在云上 2008-11-25
  • 打赏
  • 举报
回复
wsprintf()怎么用,和printf()

两者不是一个东西的,前者把数据写入宽字符串
后者把数据打印到屏幕。
pingzi_1119 2008-11-25
  • 打赏
  • 举报
回复
不好意思,我也不懂
友情up
  • 打赏
  • 举报
回复
这个我知道,我的意思是,两者在格式化输出效果上是不是相同的.可能说的不清楚,呵呵.

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧