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

std::bitset::to_string

template< class CharT, class Traits, class Alloc > std::basic_string<CharT,Traits,Allocator> to_string() const;

?

(until C++11)

template< class CharT = char, class Traits = std::char_traits<CharT>, class Allocator = std::allocator<CharT> > std::basic_string<CharT,Traits,Allocator> to_string(CharT zero = CharT('0'), CharT one = CharT('1')) const;

?

(since C++11)

将位集的内容转换为字符串。使用zero表示值为falseone表示值为true...

结果字符串包含N第一个字符对应于最后的%28N-1TH%29位和对应于第一位的最后一个字符。

参数

zero

-

character to use to represent false

one

-

character to use to represent true

返回值

转换的字符串。

二次

代码语言:javascript
复制
#include <iostream>
#include <bitset>
int main()
{
    std::bitset<8> b(42);
    std::cout << b.to_string() << '\n'
              << b.to_string('*') << '\n'
              << b.to_string('O', 'X') << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
00101010
**1*1*1*
OOXOXOXO

二次

另见

to_ulong

returns an unsigned long integer representation of the data (public member function)

to_ullong (C++11)

returns an unsigned long long integer representation of the data (public member function)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com