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表示值为false和one表示值为true...
结果字符串包含N第一个字符对应于最后的%28N-1TH%29位和对应于第一位的最后一个字符。
参数
zero | - | character to use to represent false |
|---|---|---|
one | - | character to use to represent true |
返回值
转换的字符串。
例
二次
#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';
}二次
产出:
二次
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) |
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

