求对bitset.to_string的标准用法的解释

ox_thedarkness 2006-01-26 12:08:09
C++ Primer第三版,4.12 bitset Operations 这一节中详细介绍了std::bitset 类。原文声称:

"
    ....
    bitset< 32 > bitvec3( 012 );
    ....
we can convert any bitset object into a string representation using the to_string() operation:
    string bitval( bitvec3.to_string() );
    ....
"
[ C++ Primer,3rd, P170~ 171 ]

然而在 VC 7.1 / DEV C++ 4.9.8 中这样的操作都是编译期错误:

=========================
std::bitset< 32 > bts;
bts.to_string();
=========================

bitset::to_string()在 VC 7.1中的原型返回 basic_string<_Elem,_Traits,_Ax> ,而to_string函数模版没有直接指派这三个参数。
调用时必须
=========================
a.to_string< char, std::char_traits<char>, std::allocator< char > > ();
=========================

我想问一下,究竟哪个符合C++标准? 难道C++ Primer仍然不是最纯正的ANSI C++么? 或者VC和DevC++编译器在这一点上不符合标准? 又或者标准变迁了?
如果C++ Primer在某些地方犯了类似错误,那么我读完他之后应该读什么书?
...全文
263 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ox_thedarkness 2006-01-27
  • 打赏
  • 举报
回复
我想知道 C++ Primer的是否是错的?或者只是遵循了不同的标准?
fangrk 2006-01-26
  • 打赏
  • 举报
回复
a.to_string< char, std::char_traits<char>, std::allocator< char > > ();
这个没错,BS的TCPL也是这么写的

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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