Hello. I'm writing DOS program with Visual C++ 6 and i want to log date and time to file. I'm new at programming so please tell me all #include <> and full syntax :) Also I tried time() but i recieved error:
error C2064: term does not evaluate to a function.

Thank you

What you need to include is <ctime>.

error C2660: 'time' : function does not take 0 parameters
What do i need to put into brackets? In function time ()?
And how can i log system date and time into file?

Yes you need to include <ctime> as mike_2000_17 told you, and here's some help on using it:

#include <iostream>
#include <ctime>
using namespace std;

int main()
{
time_t *rawtime = new time_t; // we'll get the time here by time() function.
struct tm * timeinfo; /* we'll get the time info. (sec, min, hour, etc...) here from rawtime by the localtime() function */

time(rawtime); // Get time into rawtime
timeinfo = localtime(rawtime); // Get time info into timeinfo

cout << "Time now is " << timeinfo->tm_hour << ":" << timeinfo->tm_min << ":" << timeinfo->tm_sec << endl;

cin.get(); // pause
return 0;
}

members of struct tm

int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;

Thank you. But how can i log time and date to file?

Thank you. But how can i log time and date to file?

you need to include <fstream> to write and read from files, here's a simple example of what you want:

#include <iostream>
#include <ctime>
#include <fstream>
using namespace std;

int main()
{
time_t * rawtime = new time_t;
struct tm * timeinfo;
time(rawtime);
timeinfo = localtime(rawtime);

ofstream file("Time.txt"); // File output stream, the file that we'll write to it
if(!file) { // if can't open file
cout << "Error while creating file!";
cin.get(); // pause
return 1;
}

file << asctime(timeinfo);
file.close();

cout << "Time wrote successfully!" << endl;
cin.get(); // pause
return 0;
}

the asctime(struct tm*) function returns the date and time in string format

Thank you very much :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.