I'm making a simple console application that has a function that takes two arrays, one with a series of column widths, and the other a series of strings, and cout's each string then adds spaces until it reaches the next column.
I'm getting this error: error: expected primary-expression before 'int'
at the first line of my columnizer
function. I've tried changing the declaration in both the header and cpp file without success.
Here's the relevant code:
//cashier.cpp
void columnizer(int sizes[], std::string values[]){
int columnCount = (sizeof sizes) / (sizeof int);
for (int i=0; i < columnCount; i++){
string value = values[i];
cout << value;
char valueLength = sizeof value / sizeof char
char extraSpace = columnSizes[i] - valueLength;
while (extraSpace > 0){
cout << " ";
extraSpace--;
}
}
}
The call to columnizer:
//cashier.cpp
int columnSizes[5] = {7, 15, 20, 9, 9};
string headers[5] = {"Qty","ISBN","Title","Price","Total"};
...
columnizer(columnSizes, headers);
...
Header file:
//cashier.h
int cashier();
void columnizer(int sizes[], std::string values[]);