creating dat file with increasing number of order in visual c++ -


i have

particle:: add_particle(int i)       {           ofstream fp1;         fp1.open("output/particle.dat",ios::binary);           fp1.write((char*)this,sizeof(*this));          fp1.close();            }            fp1.close();       } 

and loop addition using

for(int i=0;i<20;i++)     {              p.add_particle(i);        } 

however during each loop ,i want file name particle0.dat particle1.dat particle2.dat , on;

how can acheive in visual c++;

for( int = 0; < 20; ++i ) {     std::stringstream str;     str << "output/particle" << << ".dat";     fp1.open(str.str().c_str(), ios::binary);     ... } 

you can specify number formatting with:

str.width(2); str.fill('0'); ... 

see: http://www.cplusplus.com/reference/sstream/stringstream/?kw=stringstream


Comments

Popular posts from this blog

php - Magento - Deleted Base url key -

javascript - Tooltipster plugin not firing jquery function when button or any click even occur -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -