boost::format sprintf QString 字符串处理

来源:互联网 发布:js继承题目 编辑:程序博客网 时间:2024/06/02 07:24

boost库介绍的此函数的功能

下面是实例

/* * ===================================================================================== * *       Filename:  format.cpp * *    Description:  using namespace std; *    using boost::format; *    using boost::io::group; * *        Version:  1.0 *        Created:  2014年06月19日 14时19分55秒 *       Revision:  none *       Compiler:  gcc * *         Author:  刘浪 LiuLang (), datuhao@foxmail.com *   Organization:   * * ===================================================================================== */#include <iostream>#include <boost/format.hpp>#include <QString>using namespace std;using boost::format;int main(void){<span style="white-space:pre"></span>string str = (format("test boost format %s, %s, \%s") % "arg1" % "arg2" % "arg3").str();<span style="white-space:pre"></span>cout<<str<<endl;<span style="white-space:pre"></span>cout << format("writing %s,  x=%s : %d-th step \n") % "toto" % 40.23 % 50L; <span style="white-space:pre"></span>QString qstr = QString("SELECT hex(Block_Hash) FROM block_head where \Block_Hash=cast(0x%1 as binary)").arg(QString("headerHash.ToString().c_str()"));<span style="white-space:pre"></span>cout<<qstr.toStdString()<<endl;<span style="white-space:pre"></span>return 0;}

./src test boost format arg1, arg2, arg3writing toto,  x=40.23 : 50-th step SELECT hex(Block_Hash) FROM block_head where Block_Hash=cast(0xheaderHash.ToString().c_str() as binary)
0 0
原创粉丝点击