Before you can use the value returned by DSL_dataset::GetInt with the vector returned by DSL_dataset::GetStateNames, you need to check if the value at the specific position in your dataset was missing or not. To do that, call DSL_dataset::IsMissing, which returns true if value is missing.
The vector returned by GetStateNames does not have a special entry for the blank cells from CSV file. Your program crashes (in release mode) or asserts (in debug mode), because GetInt returns -1 for the blanks, and -1 can't be used as an index when calling std::vector's operator[].
Your code should look like this:
Code: Select all
// earlier in the program, certainly before main loop over records
string missingString = "N/A"; // application specific, may be empty string, etc.
// ...
int varIdx = columnIndex[idx];
const string stringVar& = IsMissing(varIdx, rec) ? missingString : GetStateNames(varIdx)[GetInt(varIdx, rec)];
The -1 is the default used by parser for discrete columns; if for some reason you want to use different value for blanks then:
a) create an object of DSL_datasetParseParams class and set its missingInt member to that value.
b) pass its address as 2nd argument when calling DSL_dataset::ReadFile.