Skip to content

Latest commit

 

History

History
36 lines (26 loc) · 1000 Bytes

string_literal_concatenation.md

File metadata and controls

36 lines (26 loc) · 1000 Bytes

文字列リテラルとワイド文字列リテラルの結合

  • cpp11[meta cpp]

概要

C99互換として、文字列リテラルとワイド文字列リテラルが並んでいたとき、ワイド文字列リテラルとして結合することが規定された。

それまでは、文字列リテラルとワイド文字列リテラルの結合は未定義動作だった。

#include <iostream>

int main()
{
  // s1とs2、どちらもwchar_t配列となる
  const wchar_t s1[] = "hello" L" world";
  const wchar_t s2[] = L"hello" " world";

  std::wcout << s1 << std::endl;
  std::wcout << s2 << std::endl;
}
  • std::wcout[link /reference/iostream/cout.md]

出力

hello world
hello world

参照