Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) std::ctime

 

std::ctime is an STL function to convert std::time_t to std::string.

 

#include <ctime>
#include <iostream>
#include <string>

int main()
{
  //Create a time struct
  std::time_t t;

  //Set the time struct to the current time
  std::time(&t);

  //Convert the time struct to std::string
  const std::string s = std::ctime(&t);

  //Put the time std::string on screen
  std::cout << s << '\n';
}

 

Screen output:

 

Mon Aug 2 12:37:32 2010

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict