-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtools.cpp
More file actions
50 lines (44 loc) · 1.06 KB
/
tools.cpp
File metadata and controls
50 lines (44 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// Created by Victor on 5/21/20.
//
#include "tools.h"
#include <vector>
#include <iostream>
#include <fstream>
#include <iterator>
using namespace std;
void print(vector<int> const &input) {
std::copy(input.begin(),
input.end(),
std::ostream_iterator<int>(std::cout, " "));
}
ifstream::pos_type filesize(const char* filename)
{
ifstream in(filename, std::ifstream::ate | std::ifstream::binary);
ifstream::pos_type ret = in.tellg();
return ret;
}
void write_vect(vector<int> vect, string name){
fstream f;
int* arr = &vect[0];
f.open(name, ios::out|ios::binary);
if (f){
f.write(reinterpret_cast<char*>(arr), vect.size() * 4);
f.close();
} else {
cout << "Error" << endl;
}
}
vector<int> read_vect(const char *name){
fstream f;
string loc = name;
f.open(loc, ios::in|ios::binary);
int fsize = filesize(loc.c_str());
vector<int> vect(fsize/4);
int* arr = &vect[0];
if(f){
f.read(reinterpret_cast<char*>(arr), fsize);
f.close();
}
return vect;
}