FILE* pf = NULL;
errno_t res = _wfopen_s(&pf, _T("sys.log"), _T("a,ccs=UNICODE"));
std::wstring ws_log = _T("[2015-08-07 10:50:33.045] [ERRO] 找不到指定的程序。 [FUNC:CModManager::LoadMods , LINE:44]\n");
//fwprintf_s(pf, ws_log.c_str());
fwprintf_s(pf, L"%s", ws_log.c_str());
//errno_t res = fopen_s(&pf, _T("sys.log"), _T("a"));
//std::string ws_log = "[2015-08-07 10:50:33.045] [ERRO] 找不到指定的程序。 [FUNC:CModManager::LoadMods , LINE:44]\n";
//fprintf_s(pf, ws_log.c_str());
fclose(pf);
解开非宽字节部分可以写入文件,然而宽字节的写不了中文,不知是何原因?
fwprintf_s(pf, ws_log.c_str()); 直接会在中文的地方停下;
fwprintf_s(pf, L"%s", ws_log.c_str()); 中文部分输出 ???
6 个解决方案
#1
哦,我知道了。忘了设置中文。
来个人接分吧。
来个人接分吧。
#2
fwprintf_s(pf, L"%s", ws_log.c_str());
改成
fwprintf_s(pf, _T("%s"), ws_log.c_str());
试试
改成
fwprintf_s(pf, _T("%s"), ws_log.c_str());
试试
#3
虽然你说的不对= =.
setlocal()
#4
Locale
Use the setlocale function to change or query some or all of the current program locale information. “Locale” refers to the locality (the country and language) for which you can customize certain aspects of your program. Some locale-dependent categories include the formatting of dates and the display format for monetary values. For more information, see Locale Categories.
Locale-Dependent Routines
Routine
Use setlocale Category
Setting Dependence
atof, atoi, atol Convert character to floating-point, integer, or long integer value, respectively LC_NUMERIC
is Routines Test given integer for particular condition. LC_CTYPE
isleadbyte Test for lead byte () LC_CTYPE
localeconv Read appropriate values for formatting numeric quantities LC_MONETARY, LC_NUMERIC
MB_CUR_MAX Maximum length in bytes of any multibyte character in current locale (macro defined in STDLIB.H) LC_CTYPE
_mbccpy Copy one multibyte character LC_CTYPE
_mbclen Return length, in bytes, of given multibyte character LC_CTYPE
mblen Validate and return number of bytes in multibyte character LC_CTYPE
_mbstrlen For multibyte-character strings: validate each character in string; return string length LC_CTYPE
mbstowcs Convert sequence of multibyte characters to corresponding sequence of wide characters LC_CTYPE
mbtowc Convert multibyte character to corresponding wide character LC_CTYPE
printf functions Write formatted output LC_NUMERIC (determines radix character output)
scanf functions Read formatted input LC_NUMERIC (determines radix character recognition)
setlocale, _wsetlocale Select locale for program Not applicable
strcoll, wcscoll Compare characters of two strings LC_COLLATE
_stricoll, _wcsicoll Compare characters of two strings (case insensitive) LC_COLLATE
_strncoll, _wcsncoll Compare first n characters of two strings LC_COLLATE
_strnicoll, _wcsnicoll Compare first n characters of two strings (case insensitive) LC_COLLATE
strftime, wcsftime Format date and time value according to supplied format argument LC_TIME
_strlwr Convert, in place, each uppercase letter in given string to lowercase LC_CTYPE
strtod, wcstod, strtol, wcstol, strtoul, wcstoul Convert character string to double, long, or unsigned long value LC_NUMERIC (determines radix character recognition)
_strupr Convert, in place, each lowercase letter in string to uppercase LC_CTYPE
strxfrm, wcsxfrm Transform string into collated form according to locale LC_COLLATE
tolower, towlower Convert given character to corresponding lowercase character LC_CTYPE
toupper, towupper Convert given character to corresponding uppercase letter LC_CTYPE
wcstombs Convert sequence of wide characters to corresponding sequence of multibyte characters LC_CTYPE
wctomb Convert wide character to corresponding multibyte character LC_CTYPE
_wtoi, _wtol Convert wide-character string to int or long LC_NUMERIC
Use the setlocale function to change or query some or all of the current program locale information. “Locale” refers to the locality (the country and language) for which you can customize certain aspects of your program. Some locale-dependent categories include the formatting of dates and the display format for monetary values. For more information, see Locale Categories.
Locale-Dependent Routines
Routine
Use setlocale Category
Setting Dependence
atof, atoi, atol Convert character to floating-point, integer, or long integer value, respectively LC_NUMERIC
is Routines Test given integer for particular condition. LC_CTYPE
isleadbyte Test for lead byte () LC_CTYPE
localeconv Read appropriate values for formatting numeric quantities LC_MONETARY, LC_NUMERIC
MB_CUR_MAX Maximum length in bytes of any multibyte character in current locale (macro defined in STDLIB.H) LC_CTYPE
_mbccpy Copy one multibyte character LC_CTYPE
_mbclen Return length, in bytes, of given multibyte character LC_CTYPE
mblen Validate and return number of bytes in multibyte character LC_CTYPE
_mbstrlen For multibyte-character strings: validate each character in string; return string length LC_CTYPE
mbstowcs Convert sequence of multibyte characters to corresponding sequence of wide characters LC_CTYPE
mbtowc Convert multibyte character to corresponding wide character LC_CTYPE
printf functions Write formatted output LC_NUMERIC (determines radix character output)
scanf functions Read formatted input LC_NUMERIC (determines radix character recognition)
setlocale, _wsetlocale Select locale for program Not applicable
strcoll, wcscoll Compare characters of two strings LC_COLLATE
_stricoll, _wcsicoll Compare characters of two strings (case insensitive) LC_COLLATE
_strncoll, _wcsncoll Compare first n characters of two strings LC_COLLATE
_strnicoll, _wcsnicoll Compare first n characters of two strings (case insensitive) LC_COLLATE
strftime, wcsftime Format date and time value according to supplied format argument LC_TIME
_strlwr Convert, in place, each uppercase letter in given string to lowercase LC_CTYPE
strtod, wcstod, strtol, wcstol, strtoul, wcstoul Convert character string to double, long, or unsigned long value LC_NUMERIC (determines radix character recognition)
_strupr Convert, in place, each lowercase letter in string to uppercase LC_CTYPE
strxfrm, wcsxfrm Transform string into collated form according to locale LC_COLLATE
tolower, towlower Convert given character to corresponding lowercase character LC_CTYPE
toupper, towupper Convert given character to corresponding uppercase letter LC_CTYPE
wcstombs Convert sequence of wide characters to corresponding sequence of multibyte characters LC_CTYPE
wctomb Convert wide character to corresponding multibyte character LC_CTYPE
_wtoi, _wtol Convert wide-character string to int or long LC_NUMERIC
#5
文件是unicode方式打开的,你写入字符串就可以了。设置中文是控制台输出要设置。按理不需要对文件设置
#6
#1
哦,我知道了。忘了设置中文。
来个人接分吧。
来个人接分吧。
#2
fwprintf_s(pf, L"%s", ws_log.c_str());
改成
fwprintf_s(pf, _T("%s"), ws_log.c_str());
试试
改成
fwprintf_s(pf, _T("%s"), ws_log.c_str());
试试
#3
虽然你说的不对= =.
setlocal()
#4
Locale
Use the setlocale function to change or query some or all of the current program locale information. “Locale” refers to the locality (the country and language) for which you can customize certain aspects of your program. Some locale-dependent categories include the formatting of dates and the display format for monetary values. For more information, see Locale Categories.
Locale-Dependent Routines
Routine
Use setlocale Category
Setting Dependence
atof, atoi, atol Convert character to floating-point, integer, or long integer value, respectively LC_NUMERIC
is Routines Test given integer for particular condition. LC_CTYPE
isleadbyte Test for lead byte () LC_CTYPE
localeconv Read appropriate values for formatting numeric quantities LC_MONETARY, LC_NUMERIC
MB_CUR_MAX Maximum length in bytes of any multibyte character in current locale (macro defined in STDLIB.H) LC_CTYPE
_mbccpy Copy one multibyte character LC_CTYPE
_mbclen Return length, in bytes, of given multibyte character LC_CTYPE
mblen Validate and return number of bytes in multibyte character LC_CTYPE
_mbstrlen For multibyte-character strings: validate each character in string; return string length LC_CTYPE
mbstowcs Convert sequence of multibyte characters to corresponding sequence of wide characters LC_CTYPE
mbtowc Convert multibyte character to corresponding wide character LC_CTYPE
printf functions Write formatted output LC_NUMERIC (determines radix character output)
scanf functions Read formatted input LC_NUMERIC (determines radix character recognition)
setlocale, _wsetlocale Select locale for program Not applicable
strcoll, wcscoll Compare characters of two strings LC_COLLATE
_stricoll, _wcsicoll Compare characters of two strings (case insensitive) LC_COLLATE
_strncoll, _wcsncoll Compare first n characters of two strings LC_COLLATE
_strnicoll, _wcsnicoll Compare first n characters of two strings (case insensitive) LC_COLLATE
strftime, wcsftime Format date and time value according to supplied format argument LC_TIME
_strlwr Convert, in place, each uppercase letter in given string to lowercase LC_CTYPE
strtod, wcstod, strtol, wcstol, strtoul, wcstoul Convert character string to double, long, or unsigned long value LC_NUMERIC (determines radix character recognition)
_strupr Convert, in place, each lowercase letter in string to uppercase LC_CTYPE
strxfrm, wcsxfrm Transform string into collated form according to locale LC_COLLATE
tolower, towlower Convert given character to corresponding lowercase character LC_CTYPE
toupper, towupper Convert given character to corresponding uppercase letter LC_CTYPE
wcstombs Convert sequence of wide characters to corresponding sequence of multibyte characters LC_CTYPE
wctomb Convert wide character to corresponding multibyte character LC_CTYPE
_wtoi, _wtol Convert wide-character string to int or long LC_NUMERIC
Use the setlocale function to change or query some or all of the current program locale information. “Locale” refers to the locality (the country and language) for which you can customize certain aspects of your program. Some locale-dependent categories include the formatting of dates and the display format for monetary values. For more information, see Locale Categories.
Locale-Dependent Routines
Routine
Use setlocale Category
Setting Dependence
atof, atoi, atol Convert character to floating-point, integer, or long integer value, respectively LC_NUMERIC
is Routines Test given integer for particular condition. LC_CTYPE
isleadbyte Test for lead byte () LC_CTYPE
localeconv Read appropriate values for formatting numeric quantities LC_MONETARY, LC_NUMERIC
MB_CUR_MAX Maximum length in bytes of any multibyte character in current locale (macro defined in STDLIB.H) LC_CTYPE
_mbccpy Copy one multibyte character LC_CTYPE
_mbclen Return length, in bytes, of given multibyte character LC_CTYPE
mblen Validate and return number of bytes in multibyte character LC_CTYPE
_mbstrlen For multibyte-character strings: validate each character in string; return string length LC_CTYPE
mbstowcs Convert sequence of multibyte characters to corresponding sequence of wide characters LC_CTYPE
mbtowc Convert multibyte character to corresponding wide character LC_CTYPE
printf functions Write formatted output LC_NUMERIC (determines radix character output)
scanf functions Read formatted input LC_NUMERIC (determines radix character recognition)
setlocale, _wsetlocale Select locale for program Not applicable
strcoll, wcscoll Compare characters of two strings LC_COLLATE
_stricoll, _wcsicoll Compare characters of two strings (case insensitive) LC_COLLATE
_strncoll, _wcsncoll Compare first n characters of two strings LC_COLLATE
_strnicoll, _wcsnicoll Compare first n characters of two strings (case insensitive) LC_COLLATE
strftime, wcsftime Format date and time value according to supplied format argument LC_TIME
_strlwr Convert, in place, each uppercase letter in given string to lowercase LC_CTYPE
strtod, wcstod, strtol, wcstol, strtoul, wcstoul Convert character string to double, long, or unsigned long value LC_NUMERIC (determines radix character recognition)
_strupr Convert, in place, each lowercase letter in string to uppercase LC_CTYPE
strxfrm, wcsxfrm Transform string into collated form according to locale LC_COLLATE
tolower, towlower Convert given character to corresponding lowercase character LC_CTYPE
toupper, towupper Convert given character to corresponding uppercase letter LC_CTYPE
wcstombs Convert sequence of wide characters to corresponding sequence of multibyte characters LC_CTYPE
wctomb Convert wide character to corresponding multibyte character LC_CTYPE
_wtoi, _wtol Convert wide-character string to int or long LC_NUMERIC
#5
文件是unicode方式打开的,你写入字符串就可以了。设置中文是控制台输出要设置。按理不需要对文件设置