随笔 - 455  文章 - 694  trackbacks - 0
<2009年1月>
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567


子曾经曰过:编程无他,唯手熟尔!
feedsky
抓虾
pageflakes
Rojo
狗狗
google reader
bloglines
my yahoo
newsgator
netvibes
鲜果


Locations of visitors to this page

常用链接

留言簿(50)

随笔分类(591)

随笔档案(455)

相册

BCB

Game Industry

OGRE

other

Programmers

Qt

special guys

  • bright tomorrow
  • A guy who has very close blood relationship with me!
  • 俺是山东人啊
  • One guy who often makes me cry in silent night.I love him so much, but I cannot see him any more, cause the God wanted him to be around.

WOW Stuff

搜索

  •  

积分与排名

  • 积分 - 202621
  • 排名 - 6

最新随笔

最新评论

阅读排行榜

评论排行榜

60天内阅读排行

要这样写:

printf( " 100%% " );

大家都知道吗?直接学c++,没仔细学过C的,估计不知道。

其实我是在用一个变长参数的函数时发现这个问题的,用流的话不用两个%,嘿嘿,写个例程:

#include <stdio.h>
#include 
<varargs.h>
#include 
<string>
#include 
<iostream>
#include 
<sstream>
#include 
<stdarg.h>

std::
string GetString(const char* pszFmt, );

int _tmain(int argc, _TCHAR* argv[])
{
    std::
string str0 = GetString("我叫猪头,我%d岁了, 我脂肪含量98%%!"3);

    std::ostringstream oss;
    oss 
<< "我叫猪头,我" << 3 << "岁了, 我脂肪含量98%!";

    std::cout 
<< str0 << '\n' << oss.str() << std::endl;
    
return 0;
}

std::
string GetString(const char* pszFmt, )
{
    std::
string strReturn;
    va_list args;
    va_start(args, pszFmt);

    
int len = _vscprintf(pszFmt, args);
    strReturn.resize(len);
    vsprintf(
&strReturn[0], pszFmt, args);

    va_end(args);

    
return strReturn;
}
posted on 2007-03-19 21:11 七星重剑 阅读(1144) 评论(5)  编辑 收藏 引用 所属分类: PL--c/c++

FeedBack:
# re: 汗!居然不知道变长参数如何输入百分号! 2007-03-19 23:07 bogy
这是输出吧!  回复  更多评论
  
# re: 汗!居然不知道变长参数如何输入百分号! 2007-03-20 08:43 梦在天涯
好像内容与题目不太一致哦  回复  更多评论
  
# re: 汗!居然不知道变长参数如何输入百分号! 2007-03-20 13:01 阿来
嗯,改过来  回复  更多评论
  
# re: 汗!居然不知道变长参数如何输出百分号! 2007-03-20 14:38 555
努力吧%%  回复  更多评论
  
# re: 汗!居然不知道变长参数如何输出百分号! 2007-03-26 01:00 lunny xiao
直接用c++的ostream格式化输出就行了.为什么还要用变长参数函数?  回复  更多评论
  

标题  
姓名  
主页
验证码 *
内容(提交失败后,可以通过“恢复上次提交”恢复刚刚提交的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
[使用Ctrl+Enter键可以直接提交]

相关链接:
网站导航: