c++ - exception handling -


i following core dump msg:

terminate called after throwing instance of 'std::out_of_range' what(): basic_string::substr abort - core dumped

i reading 14 digit hexadecimal number large file. periodically notice there these blank lines (well not sure is. how handle exception? maybe try catch thingy? looks below:

123456789abcde 123456789abcde 123456789abcde  123456789abcde 

i not sure hidden symbol occupying space causing issues , not sure how handle this..any ideas? maybe sample of how handle it?

you need post more code exception looks you're reading file line line , storing line in std::string, calling std::string::substr() extract 14 characters want.

assuming code looks this:

std::string str;         /* lines stored in string */ std::string substring;   /* extracted substring stored here */  /* read file line line */ // ...  substring = str.substr( index, 14 );  //extract 14 characters starting @ 'index' 

change to:

if( str.size() > index ) {   substring = str.substr( index, 14 ); } 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -