繁体   English   中英

Raspberry Pi C ++错误:无效使用不完整类型

[英]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编译程序时,我遇到以下性质的错误:

错误:无效使用不完整类型'struct main(int,char **):: tm'

错误:'struct main(int,char **):: tm'的前向解除

我也在开头遇到这个错误:

错误:此范围内未声明“localtime”

我做了一些研究,发现有类似问题的人不包括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作为名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM