- C 标准库
- C 标准库
- C++ 标准库
- C++ 库 - 主页
- C++ 库 - <fstream>
- C++ 库 - <iomanip>
- C++ 库 - <ios>
- C++ 库 - <iosfwd>
- C++ 库 - <iostream>
- C++ 库 - <istream>
- C++ 库 - <ostream>
- C++ 库 - <sstream>
- C++ 库 - <streambuf>
- C++ 库 - <原子>
- C++ 库 - <复杂>
- C++ 库 - <异常>
- C++ 库 - <功能>
- C++ 库 - <限制>
- C++ 库 - <语言环境>
- C++ 库 - <内存>
- C++ 库 - <新>
- C++ 库 - <数字>
- C++ 库 - <正则表达式>
- C++ 库 - <stdexcept>
- C++ 库 - <字符串>
- C++ 库 - <线程>
- C++ 库 - <元组>
- C++ 库 - <类型信息>
- C++ 库 - <实用程序>
- C++ 库 - <valarray>
C++ Bitset 库 - 运算符>> 函数
描述
C++ 函数std::bitset::operator>>将位集x插入字符流os。
宣言
以下是 std::bitset::operator>> 函数形式 std::bitset 标头的声明。
C++98
template<class charT, class traits, size_t N> basic_ostream<charT, traits>& operator<< (basic_ostream<charT,traits>& os, const bitset<N>& x);
C++11
template<class charT, class traits, size_t N> basic_ostream<charT, traits>& operator<< (basic_ostream<charT,traits>& os, const bitset<N>& x);
参数
os - 要写入的字符流。
x - 要写入的位集。
返回值
返回被操作的字符流,即os。
例外情况
如果发生异常,所有对象仍保持有效状态。
例子
以下示例显示了 std::bitset::operator>> 函数的用法。
#include <iostream>
#include <bitset>
#include <sstream>
using namespace std;
int main(void) {
string s = "101010";
istringstream stream(s);
bitset<2> b1;
bitset<6> b2;
/* Store first 2 bits */
stream >> b1;
cout << "b1 = " << b1 << endl;
/* Stores next 4 bits */
stream >> b2;
cout << "b2 = " << b2 << endl;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 -
b1 = 10 b2 = 001010
位集.htm