Is there a way to read a file backwards, line by line, without having to go through the file from the beginning to start reading backwards?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As per comment, a possible (quite simple) alternative would be read the lines into a
vector. For example:EDIT:
As per jrok‘s and Loki Astari‘s comments,
push_back()would be more efficient but the lines would be in file order, so reverse iteration (reverse_iterator) orstd::reverse()would be necessary: