Getting the System's Year

I'm trying to get the system's current year in integer format for a project. For that, I need to know where I can learn how to retrieve the system's time, but I don't know where to look. Does anyone know where I can find a tutorial that teaches how to use standard C++ time? Here is my broken code:

1
2
3
4
5
6
7
int main(int argc, char *argv[]) {
  time_t now = time(NULL);
  struct tm *tmData = localtime(now);
  int year = tmData->tm_year+1900;
  cout << year << endl;
  return 0;
}


I'm getting these two errors on line 3:
1
2
error: invalid conversion from 'time_t' to 'const time_t*'
error: initializing argument 1 of 'tm* localtime(const time_t*)'


Obviously I didn't convert something...
Thanks in advance!
You need to pass the address of 'now' to localtime():

 
struct tm *tmData = localtime(&now);
Topic archived. No new replies allowed.