mbstowcs, _mbstowcs_l
멀티 바이트 문자 시퀀스에 해당 시퀀스의 와이드 문자를 변환합니다.이러한 함수를 더 안전한 버전을 사용할 수 있습니다. see mbstowcs_s, _mbstowcs_s_l.
size_t mbstowcs(
wchar_t *wcstr,
const char *mbstr,
size_t count
);
size_t _mbstowcs_l(
wchar_t *wcstr,
const char *mbstr,
size_t count,
_locale_t locale
);
template <size_t size>
size_t mbstowcs(
wchar_t (&wcstr)[size],
const char *mbstr,
size_t count
); // C++ only
template <size_t size>
size_t _mbstowcs_l(
wchar_t (&wcstr)[size],
const char *mbstr,
size_t count,
_locale_t locale
); // C++ only
매개 변수
[out]wcstr
주소 너비 문자 시퀀스입니다.[in]mbstr
시퀀스의 null 주소 멀티 바이트 문자를 종료 했습니다.[in] count
최대 수의 멀티 바이트 문자로 변환 합니다.[in] locale
사용 하는 로캘.
반환 값
경우 mbstowcs 성공적으로 원본 문자열 변환 변환 된 멀티 바이트 문자 수를 반환 합니다.경우는 wcstr 인수가 NULL, 함수를 필요한 크기 (와이드 문자) 대상 문자열을 반환 합니다.경우 mbstowcs 에 잘못 된 멀티 바이트 문자가 발견 – 1을 반환 합니다.반환 값 이면 count를 null로 끝나는 와이드 문자열 수 없습니다.
![]() |
---|
확인 wcstr 및 mbstr 서로 중첩 되지 않습니다 및 count 올바르게 변환 하려면 멀티 바이트 문자 수를 반영 합니다. |
설명
mbstowcs 함수 변환의 최대 수를 count 멀티 바이트 문자 여를 가리키는 mbstr 현재 로케일에 의해 결정 됩니다 해당 와이드 문자 문자열입니다.이 결과 와이드 문자열 표시 주소 저장 wcstr*.* 일련의 호출 결과 유사 mbtowc.경우 mbstowcs 1 바이트 null 문자 ('\ 0')를 하기 전 또는 때 발견 한 count 발생 하는 변환 null 문자를 와이드 문자 null 문자 ('\ 0' L) 하 고 중지 합니다.와이드 문자열에 따라서 wcstr 만 null 문자 변환 하는 동안 발견 되 면 null로 끝나는.시퀀스 가리키는 경우 wcstr 및 mbstr 겹치는 경우 동작이 정의 되지 않습니다.
경우는 wcstr 인수는 NULL, mbstowcs null 종결자를 포함 하지 않는 변환에서 발생할 수 있는 와이드 문자 수를 반환 합니다.올바른 값을 반환 하는 null로 끝나는 소스 문자열 이어야 합니다.Null로 끝나는 수 결과 와이드 문자열을 해야 하는 경우 반환 되는 값에 추가 합니다.
If the mbstr argument is NULL, or if count is > INT_MAX에 설명 된 대로 잘못 된 매개 변수 처리기가 호출 매개 변수 유효성 검사 .실행 계속 수 있으면 errno 설정 된 EINVAL 및-1을 반환 하는 함수입니다.
mbstowcs현재 로케일에 대 한 모든 로캘 종속 동작을 사용합니다. _mbstowcs_l 대신 전달 된 로캘을 사용 하는 점을 제외 하 고 동일 합니다.자세한 내용은 로캘를 참조하십시오.
C + +에서이 함수는 최신, 보안 상응 하는 이러한 함수를 호출 하는 템플릿 오버 로드 되어 있습니다.자세한 내용은 보안 템플릿 오버 로드를 참조하십시오.
요구 사항
루틴 |
필수 헤더 |
---|---|
mbstowcs |
<stdlib.h> |
_mbstowcs_l |
<stdlib.h> |
추가 호환성 정보를 참조 하십시오. 호환성 소개에서 합니다.
예제
// crt_mbstowcs.c
// compile with: /W3
// illustrates the behavior of the mbstowcs function
#include <stdlib.h>
#include <stdio.h>
#include <locale.h>
int main( void )
{
size_t size;
int nChar = 2; // number of characters to convert
int requiredSize;
unsigned char *pmbnull = NULL;
unsigned char *pmbhello = NULL;
char* localeInfo;
wchar_t *pwchello = L"\x3042\x3043"; // 2 Hiragana characters
wchar_t *pwc;
/* Enable the Japanese locale and codepage */
localeInfo = setlocale(LC_ALL, "Japanese_Japan.932");
printf("Locale information set to %s\n", localeInfo);
printf( "Convert to multibyte string:\n" );
requiredSize = wcstombs( NULL, pwchello, 0); // C4996
// Note: wcstombs is deprecated; consider using wcstombs_s
printf(" Required Size: %d\n", requiredSize);
/* Add one to leave room for the null terminator. */
pmbhello = (unsigned char *)malloc( requiredSize + 1);
if (! pmbhello)
{
printf("Memory allocation failure.\n");
return 1;
}
size = wcstombs( pmbhello, pwchello, requiredSize + 1); // C4996
// Note: wcstombs is deprecated; consider using wcstombs_s
if (size == (size_t) (-1))
{
printf("Couldn't convert string. Code page 932 may"
" not be available.\n");
return 1;
}
printf( " Number of bytes written to multibyte string: %u\n",
(unsigned int) size );
printf( " Hex values of the " );
printf( " multibyte characters: %#.2x %#.2x %#.2x %#.2x\n",
pmbhello[0], pmbhello[1], pmbhello[2], pmbhello[3] );
printf( " Codepage 932 uses 0x81 to 0x9f as lead bytes.\n\n");
printf( "Convert back to wide-character string:\n" );
/* Assume we don't know the length of the multibyte string.
Get the required size in characters, and allocate enough space. */
requiredSize = mbstowcs(NULL, pmbhello, 0); // C4996
/* Add one to leave room for the NULL terminator */
pwc = (wchar_t *)malloc( (requiredSize + 1) * sizeof( wchar_t ));
if (! pwc)
{
printf("Memory allocation failure.\n");
return 1;
}
size = mbstowcs( pwc, pmbhello, requiredSize + 1); // C4996
if (size == (size_t) (-1))
{
printf("Couldn't convert string--invalid multibyte character.\n");
}
printf( " Characters converted: %u\n", (unsigned int)size );
printf( " Hex value of first 2" );
printf( " wide characters: %#.4x %#.4x\n\n", pwc[0], pwc[1] );
free(pwc);
free(pmbhello);
}
해당 .NET Framework 항목
해당 사항 없음. 표준 C 함수를 호출할 수 있습니다 PInvoke. 자세한 내용은 플랫폼 호출 예제.