gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
c++ time program
- User
c++ time program
- Assistant
Here is a sample C++ program that displays the current system time.
c++#include <iostream> #include <ctime> using namespace std; int main() { // get current time time_t now = time(0); // convert to string char* dt = ctime(&now); // display result cout << "The current system time is: " << dt << endl; return 0; }This program uses the
time()function from the<ctime>library to get the current system time, which is represented as the number of seconds since the Unix epoch (January 1, 1970). It then uses thectime()function to convert this to a string representation, which is displayed using thecoutstatement.