Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file names 1

Status
Not open for further replies.

JacksonGuy

IS-IT--Management
Dec 18, 2003
38
0
0
US
I am trying to come up with a way to make a random file name to output in a program. I am tried some different things using the ifstream and all of them require that you have a static filename (at least what I can get. I am trying to get something like:
f01.dat
f02.dat
........

does anyone have any ideas?

Thanks in advance
 
your going to have to code the "random" names yourself, (f01.dat, f02.dat doesn't seem very random to me!)

What is your criteria for a random name? Is it so you dont overwrite other files?

Robert Cumming
 
You don't need a static filename with fstream. Use a stringstream to generate your filename by adding the base (like "f") with your random number (like "1"). Then get a string from that stringstream using str(). Then pass that string to the fstream constructor or open method using c_str() since fstream takes filenames as const char*.

By the way, you should probably use ofstream for random output files (why would you want a random input file?)
 
I guess random is not wuitr the right word. It's mainly so that the files don't overlap, I don't ever have to access the file again. It is suppose to make a program that writes a pattern of data to a harddrive much like a low-level format. This is just part of it that I was having problems with. I now have a lead as to how to go about doing it however I just need to play around with it to see if I can get it to work.
 
Thanks uolj, That is what I ended up doing, and it worked great..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top