C ++格式化库通常可以回退到* sprintf的数字格式化? [英] Do C++ formatting libraries generally fall back to *sprintf for numeric formatting?

查看:227
本文介绍了C ++格式化库通常可以回退到* sprintf的数字格式化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道所有C ++格式化库最终是否会返回到 * sprintf 函数来格式化数字。



我问这是因为:




  • 查看Visual C ++附带的iostreams库,我可以看到数字输入到stream将会被格式化为 sprintf_s

  • Boost.Format只是使用可用的iostreams库。 li>


I am wondering whether "all" C++ formatting libraries eventually fall back to a *sprintf function to format numbers.

I am asking this because:

  • Looking at the iostreams library that comes with Visual C++, I can see that numbers input into a stream will eventuall be formatted with sprintf_s.
  • Boost.Format just uses the available iostreams library as far as I can tell.
  • FastFormat eventually uses vsprintf to format a number.

So, are there iostreams implementations that do not use *sprintf and do the formatting themselves? Are there other formatting libraries that do not forward formatting of numbers to *sprintf family of functions?

I would appreciate answers in the form of:

  • No: implementation XY uses ABC to format numbers
  • Yes: all other (e.g. iostreams) implementations I know (X, Y, Z) also forward number formatting to stdio, because ...

Please avoid overly speculative answers.

解决方案

Boost Spirit doesn't use *printf, as can be seen from the code (real.hpp and int.hpp) and the benchmarks for e.g. ints and doubles.

The benchmark pits Boost Spirit Karma's generators against Boost.Format against sprintf and std::stringstream. Only for gcc compilers does the performance of sprintf come close in that benchmark. Otherwise, Boost Spirit is the clear winner.

这篇关于C ++格式化库通常可以回退到* sprintf的数字格式化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆