Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

Thanks in advance!

share|improve this question
1  
Does the program actually crash or is it just the debugger displaying weird stuff? In the latter case, if it happens in release builds, it could just be the optimizer confusing the debugger. – Sebastian Redl 9 mins ago
What are the different configurations? – Nick 8 mins ago
It crashes. Access violation of some sort. – jasonlg3d 8 mins ago
It works fine in an RTX Release (Real-time environment) and Win32 Debug. However it dies in Win32 Release. I do not know all the details of those as I did not set them up. I'm compiling into a larger real-time environment. – jasonlg3d 7 mins ago

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.