Jump to content
  • Advertisement
Sign in to follow this  
dk32321

creating multiple text files

This topic is 4826 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

in a for loop i want to creat multiple text files but i just can figure it out i used this code but it olny creates one char* basename = "textfile"; for(int q = 1; q < 1002;q++) { cout << "Creating text file" << q <<"...." <<endl; for( int i = 0; i < 1000;i++) { char filname [256] = {0}; sprintf(filname,"%s_%i.txt",basename,i); poop.open(filname); pee.open(filname); } } poop.close(); pee.close(); } but it wont work

Share this post


Link to post
Share on other sites
Advertisement
std::string basename = "textfile";
std::string extension = ".txt";
std::ofstream file;
for (int fileNumber = 0; fileNumber < numberOfFiles; ++fileNumber)
{
std::string filename = basename + '_' + boost::lexical_cast< std::string >(fileNumber) + extension;
file.open(filename.c_str());
file.close();
}

Enigma

Share this post


Link to post
Share on other sites
Because saving a few cycles there is going to be so critical when the entire function is going to be I/O limited anyway. It's simple and it's error proof. Save the optimisation for when profiler shows need.

Enigma

Share this post


Link to post
Share on other sites
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!