Hello, I am trying to make a program that sends a file from one computer to another, as a project for myself. The below code works fine for text files, but for some reason, doesn't read the entire file if it is a binary.
sendfile.seekg (0, sendfile.end);
int flen = sendfile.tellg();
I do not know what I am doing wrong. Perhaps it is some oversight, but it looks like it should work. I am ready to answer any questions you might have.
Thx.
Here it is: ifstream sendfile(filepath.c_str(), ios::binary);
flen is an integer that finds the length of the file. It works fine. The erase part of the code is used as a fix for another bug, but is not important here.
I used this:
1 2
int bytesread = sendfile.gcount();
bool testfail = sendfile.fail();
and it showed nothing wrong. Bytesread showed the correct number of bytes, and it did not fail.