Skip to content

Latest commit

 

History

History
43 lines (30 loc) · 1.24 KB

string_literal_concatenation.md

File metadata and controls

43 lines (30 loc) · 1.24 KB

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

  • cpp11[meta cpp]

このページはC++11に採用された言語機能の変更を解説しています。

のちのC++規格でさらに変更される場合があるため関連項目を参照してください。

概要

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

参照