The task is to write simple numbers to a binary file. Numbers are taken from the interval 1 ... n. I did everything, but I can't get numbers into the console. That is, count numbers from a file. Help me find a bug.
#include <iostream> #include <cmath> #include <fstream> using namespace std; bool IsPrime(int num) { for (int i = 2; i < sqrt(num); i++) { if (num % i == 0)return false; } return true; } int main() { fstream f; int n; cout << "Input N" << endl; cin >> n; f.open("f.bin", ios::app/ios::binary); for (int i = 1; i < n; i++) { if (IsPrime(i)) { f.write((char *) &i, sizeof(i)); } } f.close(); f.open("f.bin", ios::in / ios::binary); int a; while (f.eof()) { f.read((char *) &a, sizeof(a)); cout << a << " "; } f.close(); system("pause"); return 0; }