1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <iostream>
10
11// wostream wcout;
12
13// UNSUPPORTED: no-wide-characters
14
15// RUN: %{build}
16// RUN: %{exec} %t.exe > %t.actual
17// RUN: echo -n zzzz > %t.expected
18// RUN: diff %t.expected %t.actual
19
20#include <iostream>
21
22struct custom_codecvt : std::codecvt<wchar_t, char, std::mbstate_t> {
23 using base = std::codecvt<wchar_t, char, std::mbstate_t>;
24protected:
25 result do_out(std::mbstate_t&, const wchar_t *from, const wchar_t *from_end,
26 const wchar_t *&from_next, char *to, char *to_end, char *&to_next) const {
27 while (from != from_end && to != to_end) {
28 ++from;
29 *to++ = 'z';
30 }
31 from_next = from;
32 to_next = to;
33 return ok;
34 }
35};
36
37int main(int, char**) {
38 std::locale loc(std::locale::classic(), new custom_codecvt);
39 std::wcout.imbue(loc: loc);
40 std::wcout << L"1234";
41 return 0;
42}
43

source code of libcxx/test/std/input.output/iostream.objects/wide.stream.objects/wcout-imbue.sh.cpp