c++ - 树莓派 C++ 错误 : invalid use of incomplete type

标签 c++ c linux raspberry-pi raspbian

我正在 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为了名字。

关于c++ - 树莓派 C++ 错误 : invalid use of incomplete type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33295016/

相关文章:

c++ - 标记(在标记和扫描中)函数如何追踪出可从根部访问的对象集?

c - 结构体 : dereferencing pointer to incomplete type 中的枚举

linux - 如何链接 64 位二进制文​​件生成 32 位二进制文​​件?

C++ 和 const - 访问 const 引用的成员函数

c++ - 我在哪里可以找到 arm-wince-pe-gcc 的二进制文件?

c++ - 使用 boost::gil 编写 jpeg 文件

c - 我得到了编译,但我的答案是 0

c - 使用相同的指针询问下一个值

linux - 内核模块总是卡住?

linux - epoll_event结构体(epoll)中参数的意义