[英]Raspberry Pi C++ error: invalid use of incomplete type
I am writing a C++ program on the Raspberry Pi. 我正在Raspberry Pi上编写一个C ++程序。 I am using the ctime library to get the current time and date to make it the title of a text file.
我正在使用ctime库获取当前时间和日期,使其成为文本文件的标题。 For example, where I am the current date and time is 14:51 on the 23rd October 2015. So the name of the text file will be 20151023_14_51.txt.
例如,我当前的日期和时间是2015年10月23日14:51。所以文本文件的名称将是20151023_14_51.txt。 Here is the code:
这是代码:
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");
My problem is that when I try to compile the program with gcc I am getting errors of the following nature: 我的问题是,当我尝试用gcc编译程序时,我遇到以下性质的错误:
error: invalid use of incomplete type 'struct main(int, char**)::tm'
错误:无效使用不完整类型'struct main(int,char **):: tm'
error: forward decleration of 'struct main(int, char**)::tm'
错误:'struct main(int,char **):: tm'的前向解除
I also get this error at the beginning: 我也在开头遇到这个错误:
error: 'localtime' was not declared in this scope
错误:此范围内未声明“localtime”
I did some research and found that people with similar problems weren't including sys/time.h but I have that included. 我做了一些研究,发现有类似问题的人不包括sys / time.h,但我有这个。 Here is what I include:
这是我包括的内容:
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
Does anyone have any idea of what could be causing these errors or if I am missing anything? 有没有人知道可能导致这些错误的原因或我是否遗漏了什么? Thanks.
谢谢。
struct tm
由#include <time.h>
或#include <ctime>
并使用std::tm
作为名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.