http://ly4cn.cnblogs.com/archive/2006/06/29/438382.html
更多关于bitset标准类型的介绍见:http://book.csdn.net/bookfiles/17/1001760.shtml
更多关于bitset操作符的介绍见:http://www.cplusplus.com/reference/stl/bitset/operators/

C/C++内置的输入、输出,对整数进制只支持三种:8进制、10进制、16进制。记得很久以前,有好几次想用到2进制的输入输出,最终只好自已转换。
  昨天kaikai突然发了一个POST:
【转】用bitset进行2进制输入输出kaikai:
【转】用bitset进行2进制输入输出看看能不能把这个程序改得更短
?
【转】用bitset进行2进制输入输出
【转】用bitset进行2进制输入输出#include 
<cstdio>
【转】用bitset进行2进制输入输出
int main()
 
一眼看过去,呵呵,输入输出不可省,核心还是二进制的转换问题。于是想起以前曾经做过的事情,学习多了,直觉的可以用bitset来实现。打开MSDN,查找bitset,嘿,果然有定义流输入操作符。
  写了一个测试:
【转】用bitset进行2进制输入输出#include <iostream>
【转】用bitset进行2进制输入输出#include 
<bitset>
【转】用bitset进行2进制输入输出
using namespace std;
【转】用bitset进行2进制输入输出
【转】用bitset进行2进制输入输出
void main()
呵呵,搞定了,输入2进制,输出10进制,完全正常。以后输入2进制串的时候,就不需要自已转换了。
 
补充:
  经过wang.lj 网友的提醒,才发现C库中还有一个函数,就是用来将数字串以指定的数制转换成整数的:
        i = strtol(s, &end, 2); //二进制流转换为16进制字符串

相关文章: