Hi all,
I want to write every given number of lines into the different files, which I will be passing as an command line argument. I have written a function for just dividing the file into two, but how would I divide the files for every given number. If anyone can help me that will be great.
{
i++;
cin >> number; (ex:100)
cin >> output_file; (ex:"/local/tmp/sample_1.csv")
is it possible with a for loop? how does it work?
if ( i <= number )
{
out.open(output_file.c_str(),ios::app);
}
if ( i==number+1 )
{
out.close();
output_file = output_file.erase(output_file.length() - 6);
output_file = output_file + "_2.csv";
}
if ( i >= number+1 )
{
out.open(output_file.c_str(),ios::app);
}
if ( !out.is_open() )
cerr << "Error: Could not open " << output_file << " for writing." << std::endl;
}
Thanks a lot in advance.