I have a function that parses a .csv file and tokenizes each line using a "," as the delimiter. I tokenize it into a vector. I then iterate over that vector and convert each string to a number using a template function. For some reason this works great in all but once compile configuration. I do not know the details of the configrations as they are set up by a different department. I'm hoping you guys see something glaringly wrong with what I've done here and can solve this.
Here is the iteration in question:
vector<std::string> tokens;
tokens = string_split(line);
std::vector<std::string>::iterator it;
for(it = tokens.begin(); it != tokens.end(); it++) {
int i = 0;
from_string<int>(i,*it,std::dec);
if(i != SYS_ELEC_BATTERY_VERSION) {
SysLoggerMessage("Battery Data does not match this version of the battery model!", MESSAGE_TYPE_ERROR);
return;
}
}
So at the point just before the the from_string call, *it is "3". However, when I step into the from_string function:
template <class T>
bool from_string(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&))
{
std::istringstream iss(s);
return !(iss >> f >> t).fail();
}
When stepping into the from_string, s is a BadPtr. Why this works with no problem in some configurations and not in one, I do not know. Any ideas?
Update: I should also mention, for whatever reason, this "Release" configuration does contain debug information so I am able to step into these functions. In from_string, the variable s is showing as this in the debugger:
"<Bad Ptr>" const std::basic_string<char, std::char_traits<char>,std::allocator<char>> &
Update Again The string_split function
vector<string> string_split(const string &source, const char *delimiter, bool keepEmpty) {
vector<string> results;
size_t prev = 0;
size_t next = 0;
while((next = source.find_first_of(delimiter, prev)) != string::npos)
{
if(keepEmpty || (next - prev != 0)) {
results.push_back(source.substr(prev,next-prev));
}
prev = next + 1;
}
if(prev < source.size())
{
results.push_back(source.substr(prev));
}
return results;
}
Thanks in advance!