so what should I use to get the binary without corrupting the data?
As Stauricus said, the easiest way to get stuff into SFML is to use the open/load functions. Music::openFromFile can load wav, ogg and flac. Texture::loadFromFile can load bmp, png, tga, jpg, gif, psd, hdr and pic.
But if you do want to open a binary file yourself (handy for things not part of SFML like save files, maps, etc), here's an quick example.
#include <fstream>
#include <filesystem>
int main()
{
// Path to file
std::filesystem::path p = "raw.dat";
std::error_code ec;
// Get the size of the file
auto size = std::filesystem::file_size(p,ec);
// Make sure no errors happened when getting the size
if (!ec)
{
// Allocate enough memory for it
char* data = new char[size];
// Open the file for binary reading
std::fstream in("raw.dat", std::ios::binary | std::ios::in);
// If it opened...
if (in.good())
{
// Read in the file
in.read(data, size);
// You now have the entire file sitting in data
}
// Release memory now that we are done
delete[] data;
}
return 0;
}
This is using C++17, it added the file system stuff that can check the size of a file.
Also some may prefer to use a vector or something for the data, but I just stick to simple new/delete (yeah, I learned C++ long before std existed)