14.19 Wide Strings
Both bounded and unbounded wide string types are mapped to
CORBA::WChar*
in C++. In addition, the CORBA module
defines WString_var
and WString_out
classes. Each of these classes provides the same member functions
with the same semantics as their string counterparts, except of
course they deal with wide strings and wide characters.
Dynamic allocation and deallocation of wide strings must be performed via the following functions:
// C++
namespace CORBA {
// ...
WChar *wstring_alloc(ULong len);
WChar *wstring_dup(const WChar* ws);
void wstring_free(WChar*);
};
These member functions have the same semantics as the same functions for the string type, except they operate on wide strings.
A compliant mapping implementation provides overloaded
operator<<
(insertion) and
operator>>
(extraction) operators for using
WString_var
and WString_out
directly with
C++ iostreams.
For descriptions of these member functions, see the corresponding function for Strings.
The following code snippet illustrates a code example that uses wide strings and wide characters.
// Get a string from the user:
cout << "String?";
char mixed[256]; // this should be big enough!
char lower[256];
char upper[256];
wchar_t wmixed[256];
cin >> mixed;
// Convert the string to a wide char string,
// because this is what the server will expect.
mbstowcs(wmixed, mixed, 256);
// Convert the string to upper case:
CORBA::WString_var v_upper = CORBA::wstring_dup(wmixed);
v_simple->to_upper(v_upper.inout());
wcstombs(upper, v_upper.in(), 256);
cout << upper << endl;
// Convert the string to lower case:
CORBA::WString_var v_lower = v_simple->to_lower(wmixed);
wcstombs(lower, v_lower.in(), 256);
cout << lower << endl;
// Everything succeeded:
return 0;
Parent topic: CORBA API