名前空間
変種

std::bitset<N>::to_string

提供: cppreference.com
 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ (C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
 
<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 が投げられるかもしれません。

#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 整数表現を返します
(パブリックメンバ関数) [edit]
(C++11)
データの unsigned long long 整数表現を返します
(パブリックメンバ関数) [edit]
Morty Proxy This is a proxified and sanitized view of the page, visit original site.