2

How can I include into my Visual Studio 2010 C-project langinfo.h. I've tried #include <langinfo.h>, but it seems there is no such header file in the VS 2010 environment. I need to get the starting weekday for the locale, but I now the way only using this library. So, the question is how to solve my problem: how to include langinfo.h, or how to get the current locale starting weekday.

4

2 回答 2

0

我认为,您应该使用 GetLocaleInfoEx() 函数。例如,要获取一周的开始日期,可以使用以下调用:

# if defined(_WIN32_WINNT_VISTA) && WINVER >= _WIN32_WINNT_VISTA && defined(LOCALE_NAME_USER_DEFAULT)
    GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK, wsDay, 4)
# else
    GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK, wsDay, 4)
# endif

有关此功能的更多信息,请访问http://msdn.microsoft.com/en-us/library/dd318103%28v=vs.85%29.aspx

于 2013-07-16T10:22:58.993 回答
0

这是一个小示例程序first_weekday.c,它获取一周的第一天。此外,打印使用的变量的值和大小。
GetLocalInfoEx()将一周的第一天存储在变量中week_1stday
但是,在 Windows 上,我们有:(0:Monday, ... 6:Sunday参见:LOCALE_IFIRSTDAYOFWEEK)。
因此,此处包含一个计算,以便获得0:Sunday, 1:Monday, ...
一周中第一天的数字,然后存储在first_weekday

#include <stdio.h>
#include <windows.h>

int main(
    )
{
    int       ret;
    int       first_weekday;
    DWORD     week_1stday;

    ret = GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT,
                          LOCALE_IFIRSTDAYOFWEEK | LOCALE_RETURN_NUMBER,
                          (LPWSTR) & week_1stday,
                          sizeof(week_1stday) / sizeof(WCHAR));
    /* 0:Monday, ..., 6:Sunday. */
    /* We need 1 for Monday, 0 for Sunday. */
    first_weekday = (week_1stday + 1) % 7;
    printf("ret = %d\n", ret);
    printf("sizeof(ret) = %Iu\n", sizeof(ret));
    printf("sizeof(week_1stday) = %Iu\n", sizeof(week_1stday));
    printf("sizeof(WCHAR) = %Iu\n", sizeof(WCHAR));
    printf("week_1stday = %lu\n", week_1stday);
    printf("first_weekday = %d\n", first_weekday);
    return 0;
}

另请参阅:
GetLocaleInfoEx 函数
LOCALE_IFIRSTDAYOFWEEK

于 2019-06-18T13:49:25.580 回答