Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


cftime function is not declared when compile by g++

Posted on 2004-11-15
Medium Priority
Last Modified: 2013-12-26
program: test.cc
#include <stdio.h>
#include <time.h>
main() {

                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++.

Question by:chumotan
  • 2
  • 2
LVL 86

Expert Comment

ID: 12584363
There is no such thing as 'cftime()' - I assume you meant 'ctime()':

CTIME(3)            Linux Programmer's Manual            CTIME(3)

       asctime,  ctime,  gmtime,  localtime,  mktime  - transform
       binary date and time to ASCII

       #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;

       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).
LVL 86

Expert Comment

ID: 12584373
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.
LVL 11

Expert Comment

ID: 12590189
There does seem to be a 'cftime()' function


LVL 11

Accepted Solution

avizit earned 1500 total points
ID: 12590200
I wonder if the following would work

1) use
extern "C" {
#include <time.h>

instead of the    #include <time.h>


#include <time>

instead of  #include <time.h>



Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses
Course of the Month10 days, 23 hours left to enroll

572 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question