I'm making a sorting algorithm in C++ that gets data from a binary file. The file only contains unsigned int and the first 4byte of the file show the number of elements it has. Next 4byte chunks has the unsigned integer gotta be sorted.
ifstream ifs(INPUT_FILE_NAME,ios::binary);
ifs.seekg(0,ifs.end);
int N=0;
N=(int)ifs.tellg();
vector<unsigned int> buf(N / sizeof(unsigned int));// reserve space for N/4 unsigned int
ifs.read(reinterpret_cast<char*>(buf.data()), buf.size()*sizeof(unsigned int)); // char==byte
I referenced a question "how to efficiently read a binary file into a vector C++", So, I tried to get bin file exactly into the vector. But I have no idea how to deal with it. I tried to cast char into uint but it didn't work. Can you give me a hint to make it?