Align columns/C++: Difference between revisions
m
Fixed syntax highlighting.
m (moved Column Aligner/C++ to Align columns/C++) |
m (Fixed syntax highlighting.) |
||
Line 5:
A reusable template function that handles the tokenizing, and is independent of any work that might wish to be done with the results:
<
#include <string> // for getline etc.
#include <iostream>
Line 35:
}
}
}</
A function object that fills an array with column widths:
<
struct MaxColWidthsDeterminer
Line 60:
else
m_colWidths[ nColIndex ] = max( m_colWidths[ nColIndex ], nWidth );
}</
A function object that outputs fields formatted in columns:
<
{
enum Alignment { eLeft, eRight, eCenter };
Line 114:
m_nPrevColIndex = nColIndex;
}</
The test program, that makes a pass through the data to determine the column widths, and then three more for outputting in each of the three column alignments:
<
{
const string strInput(
Line 151:
outFile << endl;
}
}</
|