mbP location of a buffer where to put the multi-byte string.
wcPP location of a handle pointing at the source, wide-character
string.
max number of characters to convert, optional, defaults to 0.
Function translates wide-character strings into multi-byte strings. The mbP pointed buffer needs to be big enough to store number of characters indicated by max. If max is not specified, the function translates wide-characters, until it detects the NULL-terminating byte, that is also written into the output buffer.
If conversion succeeds, the returned value indicates the number of bytes written into the output location, without the NULL-terminating byte (if any). When it fails, the tconv::error value is returned.
To perform the conversion, internal output character encoding is used.
// C++ source #include <cstdio> // freopen #include <iostream> // cout wcout #include "tconv.h" using namespace std; int main(){ // wchar_t 0x105 = 'a' with a tail below, static const wchar_t wcS[] = { 0x105, 'b', 'c', 'd', 'e', 0 }; const wchar_t *wcP = wcS; char mbB[16]; tconv tc(NULL, "pl_PL.iso_8859-2"); if(tc.wc_mb(mbB, & wcP, 0)==tconv::error){ wcout << L"Error at " << wcP; stdout=freopen(NULL, "w", stdout); } else cout << "Done\nString 'mbB' is: " << mbB << endl; cout << "The End" << endl; return 0; }
WARNING! According to C++ standards, the result of calling 'cout' and 'wcout' one after another on the same stream (stdout), is known as "undefined behaviour". The stream should be closed and opened again to reset its character width support.