Jump to content
  • Advertisement
Sign in to follow this  
discodowney

adding numbers to name when creating files

This topic is 2587 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So i have a piece of code that is creating 10 files. Currently it is hard coded so it creates the files "blah\folder\filename0", "blah\folder\filename1", etc.


makeFile(param1, "blah\\folder\\filename0", param3, param4);
makeFile(param1, "blah\\folder\\filename1", param3, param4);

Where the second param is "const char* name".

Ill have to remove the const from the parameter, but is there a way for me to change it so i can put into a for loop and specify the number of files i want created, then some how add the number onto the end of the name?

So something like

for(int i = 0; i < numFiles; i++
makeFile(param1, "blah\\folder\\filename"+(i as char), param3, param4);

Share this post


Link to post
Share on other sites
Advertisement
Assuming C++, you can use std::stringstream to create a filename.

#include <sstream>

// ...

for(int i = 0; i < numFiles; i++)
{
std::stringstream stream;
stream << "blah\\folder\\filename" << i;
makeFile(param1, stream.str().c_str(), param3, param4);
}

For C, you could use sprintf().

There should be no need to remove the const on makeFile. const on a function parameter just means that the function is promising not to modify the value. The function can still be called on a non-const value.

Share this post


Link to post
Share on other sites
Hidden
Its giving me the following error:

error C2297: '<<' : illegal, right operand has type 'const char [24]'

Assuming that means stream cant take an array of chars using the <<

Share this post


Link to post
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!