Read binary file to string, send as char array
Posted: Fri Aug 05, 2016 5:21 am
Figured this might be a nooby question that I'm just getting sick of Googling around for.
Basically I've made a file system that sends 10,000 characters at a time from the server to the client.
The client received these 10,000 characters, then determines if it creates a new file, overwrites the file, or adds onto the file.
This works wonders when sending text-based files (like a .txt document)
However, it doesn't work when sending binary files like a .png image.
I've tried reading a file's contents (with std::ios::binary) into a std::string.
If I save the std::string contents into a file, I get the duplicated file correctly YAY.
But since I have to convert the std::string to a char[10000], I believe it's being null-terminated and the char holds 26 characters (even though the output is only something like %PNG []).
So I'm trying to convert a binary std::string to a char[] array.
I've looked at this through memcpy, strcpy, even std::copy, and nothing seems to work right.
Suggestions would be helpful.
Basically I've made a file system that sends 10,000 characters at a time from the server to the client.
The client received these 10,000 characters, then determines if it creates a new file, overwrites the file, or adds onto the file.
This works wonders when sending text-based files (like a .txt document)
However, it doesn't work when sending binary files like a .png image.
I've tried reading a file's contents (with std::ios::binary) into a std::string.
If I save the std::string contents into a file, I get the duplicated file correctly YAY.
But since I have to convert the std::string to a char[10000], I believe it's being null-terminated and the char holds 26 characters (even though the output is only something like %PNG []).
So I'm trying to convert a binary std::string to a char[] array.
I've looked at this through memcpy, strcpy, even std::copy, and nothing seems to work right.
Suggestions would be helpful.