You should use either the C++ string object or C-String for this problem. Read content from a file.
The file format is such that in each line: 1) there are three columns, and 2) each column is delimited
by |.
Output each line to stdout. The first column width should be 15, the second column width should be
8, and the third column width should be 6. If the line starts with a #, you should skip it. Moreover,
the second column should be displayed to 2 decimal places.
There might be more than 3 rows; you cannot assume only 3 rows. However, you can assume that
there are only 3 columns.
Sample input
#Test file one
C1|c2|c4
Xyz|1.2|100
Abc|5.5|200
So, given that program outline (I am not asking for you to write my code! 🙁 ) here are my thoughts about what to do…
multidimensional array, but there can be more than three rows so with that variable I don’t think I could do a multidimensional array because of that.
I also thought about reading in each line, separating it up, formatting it and then printing it out, worrying about only each line at a time. I’m figuring it to be the best way possible, but I’m open to doing anything by suggestions. I think I would do it by using some sort of end of line “delimiter”.
The only other problem I can find is that I’m supposed to ignore and skip lines based on if the leading character is a #. I’m not sure how to do that either, I think the ignore() function is a way but as I understand it starts skipping things until your limit is reached or the deliminator is found. I don’t think there is a way, using that function, to find the delim character first and then skip everything to the EOL after it.
You don’t need to store the information in array, you can read and output as it goes. For example a skeleton could look something like so