#include#include int main() { std::ifstream file("example.txt"); if (file.is_open()) { std::cout << "File opened successfully." << std::endl; std::string line; while (getline(file, line)) { std::cout << line << std::endl; } file.close(); } else { std::cout << "Unable to open file." << std::endl; } return 0; }
#includeThis code reads binary data from the file 'binary.dat' and outputs it to the console as integers. Note the use of std::ios::binary to open the file in binary mode. The std::ifstream library is part of the C++ Standard Library.#include int main() { std::ifstream file("binary.dat", std::ios::binary); if (file.is_open()) { std::cout << "File opened successfully." << std::endl; int integer; while (file.read(reinterpret_cast (&integer), sizeof(int))) { std::cout << integer << std::endl; } file.close(); } else { std::cout << "Unable to open file." << std::endl; } return 0; }