Skip to content

Latest commit

 

History

History
69 lines (53 loc) · 1.38 KB

narrow.md

File metadata and controls

69 lines (53 loc) · 1.38 KB

narrow

  • locale[meta header]
  • std[meta namespace]
  • ctype[meta class]
  • function[meta id-type]
char
  narrow(charT c,
         char dfault) const;  // (1) C++98

const charT*
  narrow(const charT* low,
         const charT* high,
         char dfault,
         char* to) const;     // (2) C++98

概要

指定されたcharT型の文字に該当するchar型の文字を取得する。

  • (1) : 文字cをchar型へ変換する。変換できない場合はdfaultを返す
  • (2) : 範囲[low, high)の各文字をchar型へ変換し、toが指す領域へ格納する

戻り値

例

#include <iostream>
#include <locale>

int main()
{
  const auto& ct = std::use_facet<std::ctype<wchar_t>>(std::locale::classic());

  // (1)
  std::cout << ct.narrow(L'a', '?') << std::endl;

  // (2)
  const wchar_t s[] = L"abc";
  char buf[4] = {};
  ct.narrow(s, s + 3, '?', buf);

  std::cout << buf << std::endl;
}
  • narrow[color ff0000]
  • std::ctype[link /reference/locale/ctype.md]
  • std::use_facet[link /reference/locale/use_facet.md]
  • std::locale::classic()[link /reference/locale/locale/classic.md]

出力

a
abc

バージョン

言語

  • C++98

関連項目