#include#include using namespace std; int main() { ifstream myfile; myfile.open("example.txt"); if (myfile.is_open()) { string line; while (getline(myfile, line)) { cout << line << endl; } myfile.close(); } return 0; }
#includeIn this example, we open a binary file called "example.bin" with the ios::binary flag to read binary data. We then read each 4-byte chunk of data from the file using the read function and store it in a char array called "buffer". We convert the 4-byte chunk to an integer value using a typecast and then print it. Finally, we close the file with the close function. Package/library:#include using namespace std; int main() { ifstream myfile; myfile.open("example.bin", ios::binary); if (myfile.is_open()) { char buffer[4]; while (myfile.read(buffer, 4)) { int value = *(int*)buffer; cout << value << endl; } myfile.close(); } return 0; }