type of value time(&now) returns

im trying to store the now value from time() to use later in the program but I get constant:
warning C4244: 'initializing' : conversion from 'time_t' to 'int', possible loss of data

I have tried int, double and float variables which don't work.

I know your supposed to consider warnings as errors so im trying to remove it
thanks for your help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<iostream>
#include<string>
#include<ctime>
using namespace std;

int main()
{
	time_t now;
	time(&now);
	int starttime = now;
	 
	cout << "Starttime is : " << starttime << endl;
	// code will pass here
	time(&now);
	if (starttime - now > 10)
	{
		//then run more code
	}
	return 0;
}
 
http://www.cplusplus.com/reference/ctime/time_t/

It says that time_t is usually an integer value, but different libraries may implement it differently, which is why you get the error.

I suggest that instead of having the starttime variable, just have two time_t variables and use difftime().

http://www.cplusplus.com/reference/ctime/difftime/
thank you, i relized i needed two time_t variables on for now and one for starttime
Topic archived. No new replies allowed.