All pastes #506989 Raw Edit

Untitled

public cpp v1 · immutable
·published 2007-05-24 09:26 UTC
rendered paste body
// read_konton.cpp// Läser från en binärfil random access.#include <iostream>#include <iomanip>#include <fstream>#include <cstdlib>#include <vector>#include "diver.h"using namespace std;bool compare(const Diver& a, const Diver &b); int main(){    vector<Diver> theDivers;     ifstream in( "divers.bin", ios::binary | ios::in );           if ( !in ) {      cerr << "Filen kunde inte öppnas." << endl;      exit( 1 );    }            while ( !in.eof() )    {            Diver temp;        in.read( reinterpret_cast< char * >( &temp ), sizeof( Diver ) );        theDivers.push_back( temp );    }        sort(theDivers.begin(), theDivers.end(), compare);        for (vector<int>::size_type i = 0; i != theDivers.size()-1; i++ )    {        cout << theDivers.at(i);    }        in.close();        return 0;}bool compare (const Diver& a, const Diver& b){    return a.getTotal() > b.getTotal();   }