C++ program on dates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • novicedelight
    New Member
    • Jul 2007
    • 2

    C++ program on dates

    hela'zZz;

    kindly tell me what to do in making c++ program on dates please...... kinda novice programmer in here.....
  • archonmagnus
    New Member
    • Jun 2007
    • 113

    #2
    What exactly are you wanting to do concerning the usage of the date? If you just want to output the date, you can use the "time" and "ctime" functions (oddly enough from the "ctime" library file) as evidenced in the following code:

    [code=cpp]
    #include <iostream>
    #include <string>
    #include <ctime>

    using namespace std;

    int main (int argc, char *argv[])
    {
    string time_string;

    time_t timeInfo;
    timeInfo = time(NULL);
    time_string = ctime(&timeInfo );

    cout<<"The current time is: "<<time_string< <endl;

    return 0;
    }
    [/code]

    Note that the value returned from "ctime" contains a newline character and is null terminated.

    Comment

    Working...