I have an array filled with 1440 values. When I am reading in the file or outputting to a file, the values are being printed horizontally until it hits the window limit and starts a new line. Is there any way to write all these values in 12 columns to the file?
void output(std::ofstream& object, double avg, double max, double min, int voltagedips, int vcount[], double svv[])
{
int i; int s = 1; int z = 0;
object << "The Average Voltage is: " << avg << "V" << std::endl;
object << "The Maximum Voltage is: " << max << "V" << std::endl;
object << "The Minimum Voltage is: " << min << "V" << std::endl;
object << "The Total Number Of Voltage Dips is: " << voltagedips << std::endl;
object << "Voltage Dips Per Hour: " << '\n' << std::endl;
for (i = 0; i < 24; i++)
{
object << "Hour " << s << '\t' << vcount[i] << std::endl;
s++;
}
object << '\n' << "Voltage Variation: " << '\n' << std::endl;
for (i = 0; i < 1440; i++)
{
object << svv[i] << "V" << '\t';
if (z % 12 == 0)
{
std::cout << std::endl;
}
z++;
}
}
for (i = 0; i < 1440; i++)
{
std::cout << std::setw(3) << e[i] << "V" << (i + 1 < 12 ? '\t' : '\n');
}
Include header file "<iomanip>" for the "setw()". This will line all your numbers to the right with each one taking three spaces and any number less than 100 being padded with spaces.
void output(std::ofstream& object, double avg, double max, double min, int voltagedips, int vcount[], double svv[])
{
int i; int s = 1; int z = 1;
object << "The Average Voltage is: " << avg << "V" << std::endl;
object << "The Maximum Voltage is: " << max << "V" << std::endl;
object << "The Minimum Voltage is: " << min << "V" << std::endl;
object << "The Total Number Of Voltage Dips is: " << voltagedips << std::endl;
object << "Voltage Dips Per Hour: " << '\n' << std::endl;
for (i = 0; i < 24; i++)
{
object << "Hour " << s << '\t' << vcount[i] << std::endl;
s++;
}
object << '\n' << "Voltage Variation: " << '\n' << std::endl;
for (i = 0; i < 1440; i++)
{
object << svv[i] << "V" << '\t';
if (z % 12 == 0)
{
object << '\n';
}
z++;
}
}