Input file format problem into array of structs

Pages: 12
closed account (DSLq5Di1)
1
2
3
4
5
6
7
8
9
state_info si;
const int state_col = 5, cap_col = 20, pop_col = 40;

size_t end = line.find_last_not_of(' ', cap_col - 1);
// Back track from the first character of the capital column until we find a character
// that is not whitespace, this will give you the end character of your state column.

si.state = line.substr(state_col, end - state_col + 1); // Args for substr are the starting value,
// and # of characters to copy, so you need to minus the start from the end in the 2nd argument. 

si.state will now contain the full string of your state column, rejoice! I'll leave you to figure out the rest.

Regarding the population value, see here:-
http://stackoverflow.com/questions/6373513/currency-formatting-with-c
Thank you sloppy 9!
Topic archived. No new replies allowed.
Pages: 12