Problem mit time.h und struct tm



  • Hallo,
    folgender Programmcode:

    int datum() {
    	 time_t packed_now;
    	 time(&packed_now);
    	 struct tm* now = localtime(&packed_now);
    	 int date = now.tm_year + now.tm_month + now.tm_day;
    	 return date;
    }
    

    Nun kommen folgende Fehlermeldungen:

    backup.cpp: In function int datum()': backup.cpp:41: error: request for member \tm_year' in `now', which is of
    non-class type tm*' backup.cpp:41: error: request for member \tm_month' in `now', which is of
    non-class type tm*' backup.cpp:41: error: request for member \tm_day' in `now', which is of
    non-class type `tm*'

    Wo liegt das Problem? Ich kenne mich leider nicht aus mit Pointern (bin noch am lernen).



  • Hallo,

    wenn now ein Zeiger ist, dann greift man mit dem "->"-Operator auf die Member zu:

    int datum() {
         time_t packed_now;
         time(&packed_now);
         struct tm* now = localtime(&packed_now);
         int date = now->tm_year + now->tm_month + now->tm_day;
         return date;
    }
    

    MfG


Anmelden zum Antworten