Hello. I want to copy the last 4 bytes from a specific line from a text file (ie, always line 5). What is the best method to use once I open the file for reading. ie, How do I jump to line 5, then copy the last 4 bytes.
Read 5 lines.
Get the length of line 5.
Back up 4 characters from the end of the line.
What is so hard?
If the records were fixed length you could calculate the postion and position directly to the spot, but you stated this was a text file so the assumption is the lines are variable length.
size_t n = 5;
std::string line;
while ( n && std::getline( YourFileStream, line ) ) --n;
if ( n == 0 )
{
line.assign( line, line.size() < 4 ? 0 : line.size() - 4, std::string::npos );
// other stuff with line
}