cast from time_t to int

This is a discussion on cast from time_t to int within the C++ Programming forums, part of the General Programming Boards category; How do I cast a time_t value to int, correctly?...

  1. #1
    Politics&Cpp geek Da-Nuka's Avatar
    Join Date
    Oct 2004
    Posts
    104

    cast from time_t to int

    How do I cast a time_t value to int, correctly?

  2. #2
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    static_cast<type> object

  3. #3
    Politics&Cpp geek Da-Nuka's Avatar
    Join Date
    Oct 2004
    Posts
    104
    or.. will casting be enough?
    Or do I need to call something like a convert-function?

  4. #4
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Code:
    time_t the_time; // declare a time_t variable
    long int x; // declare a long int
    the_time = time(0); // initialize the time_t variable with the system time
    x = static_cast<int> the_time; // case the time_t variable to a long int
    The Microsoft libraries use a long int for time_t, so this cast ought not to cause problems.
    Last edited by joshdick; 04-06-2005 at 08:41 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. NEED HELP READING FILE and PRINTING
    By geoffr0 in forum C Programming
    Replies: 4
    Last Post: 04-16-2009, 06:26 PM
  2. memory leak
    By aruna1 in forum C++ Programming
    Replies: 3
    Last Post: 08-17-2008, 11:28 PM
  3. Replies: 2
    Last Post: 03-24-2006, 08:36 PM
  4. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 06:20 AM
  5. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-02-2003, 12:26 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21