2 Replies - 483 Views - Last Post: 01 June 2009 - 10:54 AM Rate Topic: -----

#1 red_4900  Icon User is offline

  • Code T(h)inkers
  • member icon

Reputation: 21
  • View blog
  • Posts: 1,119
  • Joined: 22-February 08

Accessing structure's data.

Posted 01 June 2009 - 10:45 AM

I'm trying to access the tm_min variable in ctime library.

#include<iostream>
#include<ctime>
using namespace std;
int main(void){
	struct tm *current;
	time_t raw;
	current = localtime(&raw);
	
	cout<<current.tm_min;
	
	return 0;
}


And I get error saying Structure required on left side of . or * in function main.. What did I did wrong?
Is This A Good Question/Topic? 0
  • +

Replies To: Accessing structure's data.

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3093
  • View blog
  • Posts: 19,139
  • Joined: 14-September 07

Re: Accessing structure's data.

Posted 01 June 2009 - 10:47 AM

You made it a pointer to that struct so you need to use -> or dereference then access members.


edit:

#include<iostream>
#include<ctime>
using namespace std;
int main(void){

	struct tm *current;
	time_t raw;
	time(&raw);
	current = localtime(&raw);
   
	cout<<current->tm_min;
   
	return 0;
}



I'd call time on raw before calling localtime, i was getting an exception error without it.

This post has been edited by KYA: 01 June 2009 - 10:50 AM

Was This Post Helpful? 0
  • +
  • -

#3 red_4900  Icon User is offline

  • Code T(h)inkers
  • member icon

Reputation: 21
  • View blog
  • Posts: 1,119
  • Joined: 22-February 08

Re: Accessing structure's data.

Posted 01 June 2009 - 10:54 AM

...omg. Simple error and I could not figure that out.

This is what you get after not coding much for the past 3 months. :(

edit : Forgot something. Thanks KYA. :)

This post has been edited by red_4900: 01 June 2009 - 10:55 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1