Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // open file
- fstream file(file_name, ios::in | ios::binary);
- int vertices_count = 0;
- long long edges_count = 0;
- // read header
- file.read((char*)(&vertices_count), sizeof(int));
- file.read((char*)(&edges_count), sizeof(long long));
- // print graph
- cout << "Graph has " << vertices_count << " vertices" << endl;
- cout << "Graph has " << edges_count << " edges" << endl;
- // get & print graph data for WEIGHTED graph
- for(long long i = 0; i < edges_count; i++){
- int src_id = 0, dst_id = 0;
- float weight = 0;
- // read i-th edge data
- file.read((char*)(&src_id), sizeof(int));
- file.read((char*)(&dst_id), sizeof(int));
- file.read((char*)(&weight), sizeof(float)); // remove it for unweighed graph
- //print edge data
- cout << src_id << " " << dst_id << " | " << weight << endl;
- }
- file.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement