ctype::widen
Converts a character of type char in the native character set to the corresponding character of type CharType used by a locale.
This method is potentially unsafe, as it relies on the caller to check that the passed values are correct. Consider using ctype::_Widen_s instead.
CharType widen(
char _Byte
) const;
const char *widen(
const char* _First,
const char* _Last,
CharType* _Dest
) const;
Parameters
_Byte
The character of type char in the native character set to be converted._First
A pointer to the first character in the range of characters to be converted._Last
A pointer to the character immediately following the last character in the range of characters to be converted._Dest
A pointer to the first character of type CharType in the destination range that stores the converted range of characters.
Return Value
The first member function returns the character of type CharType that corresponds to the parameter character of native type char.
The second member function returns a pointer to the destination range of characters of type CharType used by a locale converted from native characters of type char.
Remarks
The first member function returns do_widen(_Byte). The second member function returns do_widen(_First, _Last, _Dest).
备注
Any specialization of ctype that overrides this method must also override the ctype::_Widen_s method.
Example
// ctype_widen.cpp
// compile with: /EHsc /W3
#include <locale>
#include <iostream>
using namespace std;
int main( )
{
locale loc1 ( "English" );
char *str1 = "Hello everyone!";
wchar_t str2 [16];
// Note:: ctype::widen is potentially unsafe, consider
// using ctype::_Widen_s instead.
bool result1 = (use_facet<ctype<wchar_t> > ( loc1 ).widen
( str1, str1 + strlen(str1), &str2[0] ) != 0); // C4996
str2[strlen(str1)] = '\0';
cout << str1 << endl;
wcout << &str2[0] << endl;
ctype<wchar_t>::char_type charT;
charT = use_facet<ctype<char> > ( loc1 ).widen( 'a' );
}
Hello everyone!
Hello everyone!
Requirements
Header: <locale>
Namespace: std