C++ 关于strftime的一个问题

C++ 关于strftime的一个问题,c++,c,datetime,time,C++,C,Datetime,Time,问题很简单,“假设我们有一个整数1#include #包括 大小月名称(字符*buf,大小月,整数月) { struct tm t={0}; t、 tm_mon=month-1;//根据'struct tm'的需要将第1..12个月转换为第0..11个月 返回strftime(buf、大小、%B、&t); } int main(int argc,char*argv[]) { char-buf[10]; monthName(buf,sizeof(buf),9); printf(“%s\n”,buf

问题很简单,“假设我们有一个整数1
#include
#包括
大小月名称(字符*buf,大小月,整数月)
{
struct tm t={0};
t、 tm_mon=month-1;//根据'struct tm'的需要将第1..12个月转换为第0..11个月
返回strftime(buf、大小、%B、&t);
}
int main(int argc,char*argv[])
{
char-buf[10];
monthName(buf,sizeof(buf),9);
printf(“%s\n”,buf);
返回0;
}
#包括
#包括
大小月名称(字符*buf,大小月,整数月)
{
struct tm t={0};
t、 tm_mon=month-1;//根据'struct tm'的需要将第1..12个月转换为第0..11个月
返回strftime(buf、大小、%B、&t);
}
int main(int argc,char*argv[])
{
char-buf[10];
monthName(buf,sizeof(buf),9);
printf(“%s\n”,buf);
返回0;
}

tm.tm\u mon=n-1;
/*范围是0..11*/我的编译器显示:“请求非结构或联合中的成员`tm\u mon'”@n:哪个编译器?在哪个操作系统上?@nthrgeek:如果您有一个指针并且使用了
而不是
->
(此答案中的代码将起作用)
tm.tm\u mon=n-1;
/*范围为0..11*/我的编译器显示:“请求非结构或联合中的成员`tm\u mon'”@n:哪个编译器?在哪个操作系统上?@nthrgek:如果您有一个指针,并使用
而不是
->
(此答案中的代码将起作用。)
struct tm tm = {0};
tm.tm_mon = n - 1;
strftime(s, len, "%B", &tm);
#include <stdio.h>
#include <time.h>

size_t monthName( char* buf, size_t size, int month)
{
    struct  tm t = {0};

    t.tm_mon = month - 1;   // turn month 1..12 to 0..11 as `struct tm` wants

    return strftime( buf, size, "%B", &t);
}


int main(int argc, char* argv[])
{
    char buf[10];

    monthName( buf, sizeof( buf), 9);
    printf( "%s\n", buf);
    return 0;
}