Thread: File I/O with a current Date

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    145

    File I/O with a current Date

    I know how to do File I/O and such, but I was wanting to put the time and date on the top of one of my documents that was output. Besides typing it it how would I go about this? I copied some code for how to display the time and such during a program, but since I just copied the code I don't know how it works , and so I don't know how to write it to a file.
    Any help is well appreciated!

  2. #2
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    If the code you have got uses the tm data structure to hold the time, then all you have to do is output each member individually to the text file, or convert the time_t variable to a string and output that.
    Be a leader and not a follower.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    145

    Post The code I have...

    The code I have, and use, looks like this.

    Code:
    time_t now;
    time(&now);
    printf("Current Time: %.24s.\n", ctime(&now));
    Is this the circumstance you were talking about subdene?
    "Um...well..."
    -Kyoto Oshiro

  4. #4
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    try this.

    Code:
    #include <time.h>
    #include <fstream.h>
    
    int main(void)
    {
      const char FILE_NAME[]="Test.txt\0";
    
      char *Date;
      fstream File(FILE_NAME, ios::out);
    
      time_t now;
      time(&now);
      Date=ctime(&now);
    
      File << Date;
      File.close();
    
      getchar();
    
      return 0;
    }
    Be a leader and not a follower.

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    145
    Excellent, thank you kindly subdene.
    "Um...well..."
    -Kyoto Oshiro

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Subtle(?) File I/O Problem
    By cecomp64 in forum C Programming
    Replies: 9
    Last Post: 07-16-2008, 11:39 AM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. Replies: 3
    Last Post: 03-04-2005, 02:46 PM