最終更新日時:
が更新

履歴 編集

function
<locale>

std::numpunct::truename

string_type truename() const; // (1) C++98

概要

trueを表す文字列を取得する。

戻り値

do_truename()の呼び出し結果を返す。

#include <iostream>
#include <locale>
#include <stdexcept>

int main()
{
  for (const char* name : {"C", "en_US.UTF-8", "ja_JP.UTF-8", "de_DE.UTF-8"}) {
    try {
      std::locale loc{name};
      const auto& np = std::use_facet<std::numpunct<char>>(loc);

      std::cout << name << " : [" << np.truename() << "]" << std::endl;
    }
    catch (const std::runtime_error&) {
      // 指定した名前のロケールが利用できない場合
      std::cout << name << " : not available" << std::endl;
    }
  }
}

出力例

C : [true]
en_US.UTF-8 : [true]
ja_JP.UTF-8 : [true]
de_DE.UTF-8 : [true]

  • この文字列はstd::ios_base::boolalphaが設定されている場合のbool値の入出力で使用される
  • 主要な処理系では、いずれのロケールでもtrueを表す英語の名前が返る
  • 妥当なロケール名は処理系定義である。指定した名前のロケールが利用できない場合、std::localeのコンストラクタはstd::runtime_errorを送出し、上記の例ではnot availableが出力される

バージョン

言語

  • C++98

関連項目