time_t

M

magix

I saw below code:

std::time_t now;
std::time ( &now );
std::stringstream stream;
stream << "output_" << asctime(localtime( &now )) << ".txt" <<
std::flush;

How to convert asctime(localtime( &now )) to be timestamp format like
20060930130102 ?

Thanks & Regards.
 
G

Gavin Deane

magix said:
I saw below code:

std::time_t now;
std::time ( &now );
std::stringstream stream;
stream << "output_" << asctime(localtime( &now )) << ".txt" <<
std::flush;

How to convert asctime(localtime( &now )) to be timestamp format like
20060930130102 ?

How about this:

#include <ctime>
#include <sstream>
#include <string>

int main()
{
std::time_t now;
std::time ( &now );
std::stringstream stream;
stream << "output_" << asctime(localtime( &now )) << ".txt" <<
std::flush;

std::string s = stream.str();

// Write code to modify the contents of s to meet your needs.
}

If you have trouble writing the the code to modify the contents of s to
meet your needs, FAQ 5.8 explains how to post a question about code you
are having trouble with.
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8
Follow all those guidelines and you will get the help you need.

What you will have a lot less luck finding of course is anyone who will
donate their time and effort to write all your code for you. Depending
on whether this is your own programming project or something for a
class or school, asking others to do your work for you without showing
how you've attempted it yourself and where you got stuck is called
either laziness or cheating.

Gavin Deane
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

File Generation 9
CIN Input #2 gets skipped, I don't understand why. 1
How can I creat a time class? 4
Reading local time into time_t 8
time 35
Print Date 5
How can I keep second with 2 digital? 4
TF-IDF 1

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top