W
W
WildCherryCandy2014-06-06 15:42:09
C++ / C#
WildCherryCandy, 2014-06-06 15:42:09

Pointer to end of file C++

Hello.
Can't get end of file pointer.
Tried to do like this:

std::fstream f;
f.open("test.txt");
std::cout<<*f.ate;

For, as far as I know, std::ios::ate throws to the end of the file. Perhaps I'm wrong.
Please, tell me how to display a pointer to the end of the file, preferably using fstring?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tdi, 2014-06-06
@WildCherryCandy

It is not very clear how the pointer to the end of the file should look like. You want to read the last n bytes then you need to do
const int needed_bytes = 10;
f.seek(0, is.end);
int length = f.tellg();
f.seek(0, length - needed_bytes);
f.read ...
In general, a file is represented by a file descriptor, and when a file is opened, it is not completely transferred to RAM, so a const char* type pointer to some place in the file cannot be obtained without doing the operation described above. mmap exception, but that's beyond the scope of your question

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question