树莓派c++错误:无效使用不完整类型
Raspberry Pi C++ error: invalid use of incomplete type
我正在树莓派上写一个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
作为名称。
相关文章:
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 类中的字符串不命名类型
- 不完整类型错误(E0409、E0070、E0515)
- CRTP 单一实例不完整类型或非文本类型
- 使用具有结构不完整类型错误的模板
- 哪些存储了不完整类型的 STL 数据结构可以用作类成员?
- Xalloc 不命名类型
- (结构名/类名)不命名类型C++
- 是否允许类类型的 std::function 成员变量(不完整类型)?
- MSVC 在不知道类型的情况下评估上下文(和错误)
- 为什么我得到变量"Node"不是类型名称错误
- Visual Studio Code "variable " u8 的 C/C++ 扩展名 " " 不是类型名称"
- 将"std::string {aka std::basic_string}"赋值中的不兼容类型<char>
- 实例化具有不完整类型的类模板格式不正确(如果该类型是在之后定义的)
- C++ 外部类不命名类型
- 有没有办法用不变语法获得当前的类类型?
- 标准容器模板可以用不完整类型实例化吗?
- 什么时候不能用“类”代替“类型名”
- 用Clang编译c++11代码的不完整类型
- 为什么C++不能用 "super class" 类型的右值初始化 "derived class" 类型的变量?