Ok, I was going to compare the strings, but I decided that was inefficient so I switched to integers.
// I'm using strings
#include <string>
// I'm using stringstreams
#include <sstream>
// We need to declare the output stream we will write from inside the loop and open the file for output
ofstream ofDva("datavec_A1.dat");
// Two integers for the current datavecA index and the last datavecA index
int dvaIndex = 1;
int dvaIndexLast = dvaIndex;
// Now for the loop
for (i = 0; i < N; i++)
{
// calculate the current dvaIndex from the loop index
// change this formula as required to determine the maximum number of lines per file
// or based on the number of parts you want.
dvaIndex = 1 + i / 200;
if (dvaIndex != dvaIndexLast)
{
// Output anything necessary before we close the file
// --- fill in anything you think is appropriate
// close the file we're done with this part
ofDva.close();
// generate the new filename
ostringstream tfn;
tfn << "datavec_A" << dvaIndex << ".dat";
// open the file
ofDva.open(tfn.str().c_str());
}
dvaIndexLast = dvaIndex;
// The rest of the big loop goes here
// including the output line
ofDva << cosangle[i] << endl;
// and the histogram binning lines
}
// we're done with the loop
// close the last file we had open
ofDva.close();