Why wont a substring method work in a while loop

I was using getline(infile,line) for an out file that I had, and I tried to use line.substr(5,5); all of this was in a while loop. And the substring method throws an out of bounds exception. The substring method works fine if it's not in a while loop. So I had to change over to using a line array index. line[3]; I just wonder why it won't work in a while loop
You'd also have to check that std::str line does indeed have at least 5 substrings and that spanning 5 characters from the start of the 5th substring does not take you beyond the end of line
Good ideal, maybe some of the lines only had a few characters but some of the lines have over a 100 so I think I need to check and see how long the line is. I'm reading in the data from an output file so some lines have only a couple of characters and some have over a 100. I wonder why it reached so many characters into some lines but only a few into others. And thanks you helped me realize what I was doing wrong
Topic archived. No new replies allowed.