![]() |
A problem with File I/O names
Ok, ive tried o sort this out but i can't.
What i want to do is to create say 10 file all called 'hello.text' but i want them to have a number after them so i would get hello1.txt hello2.txt etc i know i can be done using loops and stuff but i just cant work out host to use a loop and change the number any help useful. thank you |
Use string streams or sprintf.
|
Thanks ill have a little read if i still dont get it ill come back to you
|
sprintf seems to be my best option but i have this code so far but it doesn't create the file
:
#include <iostream> |
Well, no, that just makes a name. You'll have to open the file(s) for writing to actually create it/them. To do that, declare a file object and open it for writing. Alter the name and loop around as many times as necessary. You'll probably want to create one file, write to it, or whatever your use for it is, complete your operations with it entirely, then generate the next name and do it all again (via loop). Have you used iostreams/filestreams before?
|
ive only used the basic input and output never tried to do this and i cant succed, ive tried to open the file but still no success
|
|
Here is a simple piece of code to study:
:
#include <iostream> // Included for I/O stream operationsQuote:
|
I'd use string streams if I were using C++. Why do you say that sprintf is the better option?
|
I don't say that it's better, Ruben. As a matter of fact, sprintf has been deprecated. Now ask yourself, if you were Hacker, and ALL of this was new to you, if you'd like to learn string streams at the same time as I/O and file streams, or if you'd maybe like to take one after the other. I guess I need to go back and read my posts, I don't recall saying it was the better option.
|
| All times are GMT -5. The time now is 5:11 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC