Raspberry Pi C++ error: invalid use of incomplete type
Raspberry Pi C++ error: invalid use of incomplete type
我正在 Raspberry Pi 上编写 C++ 程序。我正在使用 ctime 库获取当前时间和日期,使其成为文本文件的标题。例如,我所在的当前日期和时间是 2015 年 10 月 23 日 14:51。因此文本文件的名称将是 20151023_14_51.txt。这是代码:
FILE *f;
main(int argc, char *argv[]){
char dateiname[256]="";
time_t t = time(0);
struct tm * now = localtime(&t);
//Create and open file
sprintf(dateiname, "/home/raspbian/Desktop/%02d%02d%02d_%02d_%02d.txt",
now->tm_year+1900,
now->tm_mon+1,
now->tm_mday,
now->tm_hour,
now->tm_min;
f = fopen(dateiname, "w");
我的问题是,当我尝试使用 gcc 编译程序时,出现以下性质的错误:
error: invalid use of incomplete type 'struct main(int, char**)::tm'
error: forward decleration of 'struct main(int, char**)::tm'
我一开始也遇到这个错误:
error: 'localtime' was not declared in this scope
我做了一些研究,发现有类似问题的人没有包括 sys/time.h,但我已经包括了。这是我包含的内容:
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
有没有人知道可能导致这些错误的原因或者我是否遗漏了什么?谢谢。
struct tm
由 #include <time.h>
或 #include <ctime>
定义并使用 std::tm
作为名称。
我正在 Raspberry Pi 上编写 C++ 程序。我正在使用 ctime 库获取当前时间和日期,使其成为文本文件的标题。例如,我所在的当前日期和时间是 2015 年 10 月 23 日 14:51。因此文本文件的名称将是 20151023_14_51.txt。这是代码:
FILE *f;
main(int argc, char *argv[]){
char dateiname[256]="";
time_t t = time(0);
struct tm * now = localtime(&t);
//Create and open file
sprintf(dateiname, "/home/raspbian/Desktop/%02d%02d%02d_%02d_%02d.txt",
now->tm_year+1900,
now->tm_mon+1,
now->tm_mday,
now->tm_hour,
now->tm_min;
f = fopen(dateiname, "w");
我的问题是,当我尝试使用 gcc 编译程序时,出现以下性质的错误:
error: invalid use of incomplete type 'struct main(int, char**)::tm'
error: forward decleration of 'struct main(int, char**)::tm'
我一开始也遇到这个错误:
error: 'localtime' was not declared in this scope
我做了一些研究,发现有类似问题的人没有包括 sys/time.h,但我已经包括了。这是我包含的内容:
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
有没有人知道可能导致这些错误的原因或者我是否遗漏了什么?谢谢。
struct tm
由 #include <time.h>
或 #include <ctime>
定义并使用 std::tm
作为名称。