I'm attempting to trim the strings that I read in from a file. I read the string, trim it, then do my stuff with it. As I read through the file, I eventually reach the end, meaning the endpos+1 results in an out of range exception.
What would be the "best" way of handling this issue? Below is my trimming code.
size_t startpos = num.find_first_not_of(" ");
size_t endpos = num.find_last_not_of(" ");
num = num.substr(startpos, endpos-startpos+1); //out of range on final string read from file
My idea would be to use a try-catch block for it, but this seems very novice (I am one after all!)
Thanks!