std::bitset<N>::to_string
提供: cppreference.com
<tbody>
</tbody>
<tbody class="t-dcl-rev ">
</tbody><tbody>
</tbody>
template< class CharT, class Traits, class Alloc > std::basic_string<CharT,Traits,Allocator> to_string() const; |
(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; |
(C++11以上) | |
ビットセットの内容を文字列に変換します。 false の値を持つビットを表すために zero を、 true の値を持つビットを表すために one を使用します。
結果の文字列は、最初の文字が最後の (N-1 番目の) ビットに対応し、最後の文字が最初のビットに対応する、 N 個の文字を格納します。
引数
| zero | - | false を表すために使用する文字
|
| one | - | true を表すために使用する文字
|
戻り値
変換された文字列。
例外
std::string のコンストラクタから std::bad_alloc が投げられるかもしれません。
例
Run this code
#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
関連項目
データの unsigned long 整数表現を返します (パブリックメンバ関数) | |
(C++11) |
データの unsigned long long 整数表現を返します (パブリックメンバ関数) |