chumotan
asked on
cftime function is not declared when compile by g++
program: test.cc
#include <stdio.h>
#include <time.h>
main() {
printf("Hello!\n");
char temp[2048];
char timestamp[20];
struct timeval timeval;
gettimeofday( &timeval, 0 );
cftime( timestamp, (char *)"%h %d %H:%M:%S", &(timeval.tv_sec) );
Then the folloing errors output when i compile by using g++,
>g++ -g test.cc
test.cc: In function `int main()':
test.cc:10: error: `cftime' undeclared (first use this function)
test.cc:10: error: (Each undeclared identifier is reported only once for each fu
nction it appears in.)
This is not a problem if i use gcc and reanme the program from test.cc to test.c.
However, i need to use g++.
#include <stdio.h>
#include <time.h>
main() {
printf("Hello!\n");
char temp[2048];
char timestamp[20];
struct timeval timeval;
gettimeofday( &timeval, 0 );
cftime( timestamp, (char *)"%h %d %H:%M:%S", &(timeval.tv_sec) );
Then the folloing errors output when i compile by using g++,
>g++ -g test.cc
test.cc: In function `int main()':
test.cc:10: error: `cftime' undeclared (first use this function)
test.cc:10: error: (Each undeclared identifier is reported only once for each fu
nction it appears in.)
This is not a problem if i use gcc and reanme the program from test.cc to test.c.
However, i need to use g++.
Ooops, sorry, editing error - apart from the man page, that should have beeen
There is no such thing as 'cftime()' - I assume you meant 'ctime()'
So, change
cftime( timestamp, (char *)"%h %d %H:%M:%S", &(timeval.tv_sec) );
to read
ctime( timestamp, (char *)"%h %d %H:%M:%S", &(timeval.tv_sec) );
and it should work.
There is no such thing as 'cftime()' - I assume you meant 'ctime()'
So, change
cftime( timestamp, (char *)"%h %d %H:%M:%S", &(timeval.tv_sec) );
to read
ctime( timestamp, (char *)"%h %d %H:%M:%S", &(timeval.tv_sec) );
and it should work.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
CTIME(3) Linux Programmer's Manual CTIME(3)
NAME
asctime, ctime, gmtime, localtime, mktime - transform
binary date and time to ASCII
SYNOPSIS
#include <time.h>
char *asctime(const struct tm *timeptr);
char *ctime(const time_t *timep);
struct tm *gmtime(const time_t *timep);
struct tm *localtime(const time_t *timep);
time_t mktime(struct tm *timeptr);
extern char *tzname[2];
So, change
cftime( timestamp, (char *)"%h %d %H:%M:%S", &(timeval.tv_sec) );
to read
ctime( timestamp, (char *)"%h %d %H:%M:%S", &(timeval.tv_sec) );
and it should work.
long int timezone;
extern int daylight;
DESCRIPTION
The ctime(), gmtime() and localtime() functions all take
an argument of data type time_t which represents calendar
time. When interpreted as an absolute time value, it rep
resents the number of seconds elapsed since 00:00:00 on
January 1, 1970, Coordinated Universal Time (UTC).