I am outputting five characters of a consumer name using a char array named consumerN. The actual array in some cases is longer than five letters, and in some cases shorter. If I use setw() it doesn't chop it off at five, I am assuming that that does not work because it is a string array. I am reading info from a file and outputting to another file line by line so it is in a while loop. So I set it to left align and output byte by byte the first five in the string:
Code:
report.setf(ios::left);
report << setfill(' ') << consumerN[0] << consumerN[1] << consumerN[2] << consumerN[3] << consumerN[4];
The only problem with this is that it outputs to the report the '\0' null byte (looks like a square) if the consumerN length is 4, and if it is less than four it outputs the fifth byte from the previous consumerN. Is there an easy way to fix this??? Can I clear the consumerN after each output so as to erase as the example, the fifth byte from the previous consumerN, even if I did that though, it would not solve the output of the null byte. I do not want to do a system clear because I have other information that I need to continue storing in variables. And how do I avoid writing the null byte to the report output file and just output a space.
Thanks for any suggestions!!!