C++
应用 | Utilities

std::bitset::to_string

STD::位集::to[医]弦

template< class CharT, class Traits, class Alloc > std::basic_string 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

返回值

转换的字符串。

二次

#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_ulongreturns 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。

http://en.cppreference.com/w/cpp/实用程序/bitset/to[医]弦