[英]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.