I wrote a function to get a current date and time in format: DD-MM-YYYY HH:MM:SS. It works but let\'s say, its pretty ugly. How can I do exactly the sam
Non C++11 solution: With the header, you could use strftime. Make sure your buffer is large enough, you wouldn't want to overrun it and wreak havoc later.
#include
#include
int main ()
{
time_t rawtime;
struct tm * timeinfo;
char buffer[80];
time (&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer,sizeof(buffer),"%d-%m-%Y %H:%M:%S",timeinfo);
std::string str(buffer);
std::cout << str;
return 0;
}