首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

operators (std::bitset)

template <class CharT, class Traits, size_t N> std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const bitset<N>& x);

(1)

template <class CharT, class Traits, size_t N> std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, bitset<N>& x);

(2)

从字符流中插入或提取位集。

1%29写入位集x到字符流os好像首先将其转换为basic_string<CharT,Traits>使用to_string(),然后把它写进os使用operator<<%28,即aFormattedOutputFunction用于字符串%29。用于1和零的字符是从当前注入的区域设置中通过调用std::use_facet<std::ctype<CharT>(os.getloc()).widen()带着'1''0'作为争论。

2%29表现为FormattedInputFunction.在构造和检查哨兵对象(可能跳过前导空格)之后,提取Nis并将字符存储在位集中。x...

字符将被提取,直到任何一个。

  • N人物已经读过了,
  • 文件结束发生在is,或
  • 下一个角色都不是is.widen('0')也不is.widen('1')...

如果没有提取字符,is.setstate(ios_base::failbit)叫做。

参数

os

-

the character stream to write to

is

-

the character stream to read from

x

-

the bitset to be read or written

返回值

操作的字符流。osis...

二次

代码语言:javascript
复制
#include <bitset>
#include <iostream>
#include <sstream>
 
int main()
{
    std::string bit_string = "001101";
    std::istringstream bit_stream(bit_string);
 
    std::bitset<3> b1;
    bit_stream >> b1; // reads "001", stream still holds "101"
    std::cout << b1 << '\n';
 
    std::bitset<8> b2;
    bit_stream >> b2; // reads "101", populates the 8-bit set as "00000101"
    std::cout << b2 << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
001
00000101

二次

另见

operator<<=operator>>=operator<<operator>>

performs binary shift left and shift right (public member function)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券