读取位字符串到 bitset。
template<class CharType, class Traits, size_t Bits>
basic_istream<CharType, Traits>& operator>> (
basic_istream<CharType, Traits>& _Istr,
bitset<N>& _Right
);
参数
_Istr
输入到要插入的内容为 bitset 的字符串。_Right
接收输入流中的位的 bitset。
返回值
模板函数返回字符串 _Istr。
备注
模板函数。bitset _Right 重载 运算符>> 值存储 bitset (str),其中 str 为CharType类型,basic_string<特征,allocator<CharType> >从 _Istr提取的**&** 对象。
模板函数从 _Istr 提取元素并将这些类插入 bitset 之前:
所有元素 bitset 位输入流中提取和存储。
bitset 填满的输入流的位。
不是 0 和 1. 中输入元素时。
示例
#include <bitset>
#include <iostream>
#include <string>
using namespace std;
int main()
{
bitset<5> b1;
cout << "Enter string of (0 or 1) bits for input into bitset<5>.\n"
<< "Try bit string of length less than or equal to 5,\n"
<< " (for example: 10110): ";
cin >> b1;
cout << "The ordered set of bits entered from the "
<< "keyboard\n has been input into bitset<5> b1 as: ( "
<< b1 << " )" << endl;
// Truncation due to longer string of bits than length of bitset
bitset<2> b3;
cout << "Enter string of bits (0 or 1) for input into bitset<2>.\n"
<< " Try bit string of length greater than 2,\n"
<< " (for example: 1011): ";
cin >> b3;
cout << "The ordered set of bits entered from the "
<< "keyboard\n has been input into bitset<2> b3 as: ( "
<< b3 << " )" << endl;
// Flushing the input stream
char buf[100];
cin.getline(&buf[0], 99);
// Truncation with non-bit value
bitset<5> b2;
cout << "Enter a string for input into bitset<5>.\n"
<< " that contains a character than is NOT a 0 or a 1,\n "
<< " (for example: 10k01): ";
cin >> b2;
cout << "The string entered from the keyboard\n"
<< " has been input into bitset<5> b2 as: ( "
<< b2 << " )" << endl;
}
输入
10110
1011
10k10
要求
页眉: <bitset>
命名空间: std