69,382
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
int main(int argc,char* argv[]){
char *str="中国上海";
printf("%s\n",str);
char *locale=setlocale(LC_CTYPE,NULL);
printf("locale:%s\n",locale);
locale=setlocale(LC_CTYPE,"zh_CN.UTF-8");
printf("locale:%s\n",locale);
wchar_t *wcstr=L"北京您好";
wprintf(L"wide char string:%ls\n",wcstr);
return 0;
}
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
int main(int argc,char* argv[]){
char *locale=setlocale(LC_CTYPE,"zh_CN.UTF-8");
printf("locale:%s\n",locale);
char *str="中国上海";
printf("%s\n",str);
wchar_t *wcstr=L"北京您好";
wprintf(L"wide char string:%ls\n",wcstr);
return 0;
}
wint_t __cdecl _fputwc_nolock (
wchar_t ch,
FILE *str
)
{
if (!(str->_flag & _IOSTRG))
{
if (_textmode_safe(_fileno(str)) == __IOINFO_TM_UTF16LE
|| _textmode_safe(_fileno(str)) == __IOINFO_TM_UTF8)
{
/* binary (Unicode) mode */
if ( (str->_cnt -= sizeof(wchar_t)) >= 0 ) {
return (wint_t) (0xffff & (*((wchar_t *)(str->_ptr))++ = (wchar_t)ch));
} else {
return (wint_t) _flswbuf(ch, str);
}
}
else if ((_osfile_safe(_fileno(str)) & FTEXT))
{
int size, i;
char mbc[MB_LEN_MAX];
/* text (multi-byte) mode */
if (wctomb_s(&size, mbc, MB_LEN_MAX, ch) != 0) // 这里会根据转换为locale相关的mb
{
/*
* Conversion failed; errno is set by wctomb_s;
* we return WEOF to indicate failure.
*/
return WEOF;
}
for ( i = 0; i < size; i++)
{
if (_putc_nolock(mbc[i], str) == EOF)
return WEOF;
}
return (wint_t)(0xffff & ch);
}
}
/* binary (Unicode) mode */
if ( (str->_cnt -= sizeof(wchar_t)) >= 0 )
return (wint_t) (0xffff & (*((wchar_t *)(str->_ptr))++ = (wchar_t)ch));
else
return (wint_t) _flswbuf(ch, str);
}
#undef putwc
wint_t __cdecl putwc (
wchar_t ch,
FILE *str
)
{
return fputwc(ch, str);
}
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
int main(int argc,char* argv[])
{
setlocale(LC_CTYPE,"zh_CN.UTF-8");
char *str="中国上海";
printf("%s\n",str);
wchar_t *wcstr=L"北京您好";
printf("wide char string:%ls\n",wcstr);
return 0;
}
wchar_t *wcstr=L"北京您好";
都编译不了……换成英文就行!