最終更新日時(UTC):
が更新

履歴 編集

文字列リテラルとワイド文字列リテラルの結合(C++11)

概要

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;
}

出力

hello world
hello world

参照