简体   繁体   中英

Raspberry Pi C++ error: invalid use of incomplete type

I am writing a C++ program on the Raspberry Pi. I am using the ctime library to get the current time and date to make it the title of a text file. 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. 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:

error: invalid use of incomplete type 'struct main(int, char**)::tm'

error: forward decleration of 'struct main(int, char**)::tm'

I also get this error at the beginning:

error: 'localtime' was not declared in this scope

I did some research and found that people with similar problems weren't including sys/time.h but I have that included. 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作为名称。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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