请输入您要查询的百科知识:

 

词条 _wsetlocale
释义

C语言函数

函数简介

函数名称:_wsetlocale

函数原型:

wchar_t *_wsetlocale(

int category,

const wchar_t *locale

);

函数功能及返回值:设置、改变或返回当前的地域信息,若成功则返回一个指向地域信息字符串的指针

所属库:locale.h或wchar.h

相关函数:setlocale、localeconv

参数说明

详见

程序示例

// crt_setlocale.cpp

//

// This program demonstrates the use of setlocale when

// using two independent threads.

//

#include <locale.h>

#include <process.h>

#include <windows.h>

#include <stdio.h>

#include <time.h>

#define BUFF_SIZE 100

// Retrieve the date and time in the current

// locale's format.

int get_time(unsigned char* str)

{

__time64_t ltime;

struct tm thetime;

// Retieve the time

_time64(&ltime);

_gmtime64_s(&thetime, &ltime);

// Format the current time structure into a string

// using %#x is the long date representation,

// appropriate to the current locale

if (!strftime((char *)str, BUFF_SIZE, "%#x",

(const struct tm *)&thetime))

{

printf("strftime failed!\");

return -1;

}

return 0;

}

// This thread sets its locale to German

// and prints the time.

unsigned __stdcall SecondThreadFunc( void* pArguments )

{

unsigned char str[BUFF_SIZE];

// Set the thread local

printf("The thread locale is now set to %s.\",

setlocale(LC_ALL, "German"));

// Retrieve the time string from the helper function

if (get_time(str) == 0)

{

printf("The time in German locale is: '%s'\", str);

}

_endthreadex( 0 );

return 0;

}

// The main thread spawns a second thread (above) and then

// sets the locale to English and prints the time.

int main()

{

HANDLE hThread;

unsigned threadID;

unsigned char str[BUFF_SIZE];

// Configure per-thread locale to cause all subsequently created

// threads to have their own locale.

_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);

// Retrieve the time string from the helper function

printf("The thread locale is now set to %s.\",

setlocale(LC_ALL, "English"));

// Create the second thread.

hThread = (HANDLE)_beginthreadex( NULL, 0, &SecondThreadFunc,

NULL, 0, &threadID );

if (get_time(str) == 0)

{

// Retrieve the time string from the helper function

printf("The time in English locale is: '%s'\\", str);

}

// Wait for the created thread to finish.

WaitForSingleObject( hThread, INFINITE );

// Destroy the thread object.

CloseHandle( hThread );

}

随便看

 

百科全书收录4421916条中文百科知识,基本涵盖了大多数领域的百科知识,是一部内容开放、自由的电子版百科全书。

 

Copyright © 2004-2023 Cnenc.net All Rights Reserved
更新时间:2025/1/31 22:59:09