Fil skrivning af med Mega long long array
Her er en lille gåde jeg håber nogen kan løse. Jeg vil kunne skrive og læse min. 1 mio. long long til og fra en fil. Dette skal kunne gøre mange gang i løbet af programmet levetid. Med dette forsøgs program gives der en fejlmeddelse når man køre programmet. Jeg bruger .net 2003:#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
int main(void)
{
long long base[100000];
long long base1[100000];
long long base2[100000];
long long base3[100000];
long long base4[100000];
long long base5[100000];
long long base6[100000];
long long base7[100000];
long long base8[100000];
long long base9[100000];
ifstream loadf("Baseprimes.bpf");
for (long long i = 0; i<100000; i++)
loadf >> *(base + i);
for (long long i = 0; i<100000; i++)
loadf >> *(base1 + i);
for (long long i = 0; i<100000; i++)
loadf >> *(base2 + i);
for (long long i = 0; i<100000; i++)
loadf >> *(base3 + i);
for (long long i = 0; i<100000; i++)
loadf >> *(base4 + i);
for (long long i = 0; i<100000; i++)
loadf >> *(base5 + i);
for (long long i = 0; i<100000; i++)
loadf >> *(base6 + i);
for (long long i = 0; i<100000; i++)
loadf >> *(base7 + i);
for (long long i = 0; i<100000; i++)
loadf >> *(base8 + i);
for (long long i = 0; i<100000; i++)
loadf >> *(base9 + i);
loadf.close();
FILE *fbase = fopen("rimes.bpf", "wb");
fwrite(base, sizeof(long long), 100000, fbase);
cout << endl << "Prime # 100000 is: " << base[99999] << endl;
fwrite(base1, sizeof(long long), 100000, fbase);
cout << endl << "Prime # 200000 is: " << base1[99999] << endl;
fwrite(base2, sizeof(long long), 1000000, fbase);
cout << endl << "Prime # 300000 is: " << base2[99999] << endl;
fwrite(base3, sizeof(long long), 100000, fbase);
cout << endl << "Prime # 400000 is: " << base3[99999] << endl;
fwrite(base4, sizeof(long long), 100000, fbase);
cout << endl << "Prime # 500000 is: " << base4[99999] << endl;
fwrite(base5, sizeof(long long), 100000, fbase);
cout << endl << "Prime # 600000 is: " << base5[99999] << endl;
fwrite(base6, sizeof(long long), 100000, fbase);
cout << endl << "Prime # 700000 is: " << base6[99999] << endl;
fwrite(base7, sizeof(long long), 100000, fbase);
cout << endl << "Prime # 800000 is: " << base7[99999] << endl;
fwrite(base8, sizeof(long long), 100000, fbase);
cout << endl << "Prime # 900000 is: " << base8[99999] << endl;
fwrite(base9, sizeof(long long), 100000, fbase);
cout << endl << "Prime # 1000000 is: " << base9[99999] << endl;
fclose(fbase);
FILE *rimes = fopen("rimes.bpf", "rb");
fread(base2, sizeof(long long), 100000, rimes);
fclose(rimes);
cout << endl << endl << "Prime # 100000 (read) is: " << base2[99999] << endl;
cin >> base2[456]; //Så jeg lige kan se mit output
return 0;
}