[try Beta version]
Not logged in

 
Date/Time Filename

Aug 13, 2010 at 8:43pm
I can not figure out how to get the date and time into a filename.

Here is the original snippet of code:
1
2
3
4
	cout << "Enter file name (without extension): ";
	cin >> fileName;
        dataName = fileName  + ".d";
	timeName = fileName  + ".t";


This works perfectly. However, I need the date/time in the file name instead of the user input.

1
2
3
4
5
	
        // cout << "Enter file name (without extension): ";
	// cin >> fileName;
        dataName = {NEED DATE/TIME}  + ".d";
	timeName = {NEED DATE/TIME}  + ".t";


Please note, I know exactly zero about C or C++

Thanks for any help.

-SNT
Aug 13, 2010 at 9:03pm
Use stringstreams
eg:
1
2
3
4
5
6
7
8
9
// #include <sstream>
int hours = 14, minutes = 30;

stringstream ss;
ss << hours << ':' << minutes << ".t"

string name = ss.str(); // get a string from the stream

const char *c_name = ss.str().c_str(); // get a C string from the stream 

The result will be 14:30.t
Aug 13, 2010 at 9:05pm
Last edited on Aug 13, 2010 at 9:06pm
Aug 13, 2010 at 9:47pm
Thanks for the replies.

Bazzy,
Would that get the current date/time? It looks as though it would just output whatever hours and minutes are set to.

moorecm,
Yeah, I saw that page and read through quite a few times. However, I know absolutely nothing about programming so I can not make heads or tails of that info.

Last edited on Aug 13, 2010 at 9:49pm
Aug 13, 2010 at 9:53pm
I know absolutely nothing about programming so I can not make heads or tails of that info.
Why are you writing a program if you know nothing about programming?

Would that get the current date/time?
Nope, you need to adjust that using functions like those moorecm linked
Aug 13, 2010 at 9:55pm
Why are you writing a program if you know nothing about programming?


Why does that matter?
Aug 13, 2010 at 10:19pm
Because if you have no idea on how to it, it's hard that you will be successful
You should at least have some basic knowledge, try the tutorials: http://www.cplusplus.com/doc/tutorial/
Aug 13, 2010 at 10:32pm
Oh to live in the black white world that you appear to be in. ;)

I understand that the circumstances are unknown, so leave it at that. If you or someone else does not know how to do it then fine leave it that. However, if you do, I would appreciate the steps. I do not have the time or the inclination to learn this stuff or to go through the numerous pages I have already looked at (including the ones linked here). I am only tackling this due to circumstance. I can not stand programming for this very reason. Something that should be so simple is made to be a ridiculous task. I could have done this simple thing in VB quite easily, but C++...nonsensical.

Aug 14, 2010 at 8:28am
C++ is powerfull, and thus more complicated. Once you learn it it's easy to use... just takes time.
Aug 14, 2010 at 9:25am
Something that should be so simple is made to be a ridiculous task.


That's incredibly simple, wtf are you talking about? Oh wait...VB. LOL
Topic archived. No new replies allowed.