I'm attempting to determine if the last element in a filesystem path is a certain value by comparing it to a string. However, at run-time, the program is failing an assertion whenever I attempt to move the iterator.
Expression: cannot dereference string iterator because the iterator was invalidated.
The cout statement functions correctly and I don't know where I'm invalidating the iterator. Ideally, I would set my iterator to parent_path().end() and then decrement it once to get the last valid element but I don't seem to be able to do this.
It seems as if I've scoured the entire filesystem reference...twice. I saw that example, too. It helped and thanks anyway.
Since path.filename() and path.has_filename() only return or act on the last element of a path, regardless if the element represents a directory or a file, they aren't as useful as I originally thought. I've used the file_status class to better assess the nature of the last and second to last elements of a path (to help solve my problem), something like: