C++ iostream wcerr Object
Example
Use the wcerr object to output an error message:
int x = 5;
int y = 0;
if (y == 0) {
wcerr << L"Division by zero: " << x << L" / " << y << L"\n";
} else {
wcout << (x / y);
}
Definition and Usage
The wcerr object is used to output error messages with wide characters. It works like cerr, but it outputs wchar_t data instead of char data. Like cerr, it is not buffered, so the messages are written right away.
A wide character (wchar_t) is a character type that can store more different characters than char. Wide text is written with an L in front, like L"Hello".
The wcerr object is defined in the <iostream> header file.
Note: To avoid problems, do not mix wide and normal streams in one program. Use wcerr together with wcout, and cerr together with cout.
Syntax
wcerr << value;
Parameter Values
| Parameter | Description |
|---|---|
| value | Required. The value to output, like wide text (L"text"), a number, or a wchar_t character. |
Technical Details
| Returns: | The << operator returns a reference to wcerr itself, so you can use << many times in one statement. |
|---|