C++ vector to binary file | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C++ vector to binary file

Hello I have a task to put random vector in a binary file and read this binary file to check if everything is ok. I dont know how to read binary file i made something like this and it isn't working. vector<float> binaryReading(){ string filename ="tekstBinary.txt"; ifstream input(filename, ios::binary); if (input) { int i; while (input.read(reinterpret_cast<char*> (i), sizeof(i))) cout << i << " "; } input.close(); }

3rd Jan 2018, 9:56 PM
mercin
mercin - avatar
2 Answers
0
you need to give the pointer to the "i" in the reinterpret cast parameter, that is "&i"
10th Sep 2019, 9:50 PM
Data
Data - avatar
0
ok nvm i didnt see the date
10th Sep 2019, 9:50 PM
Data
Data - avatar