-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathloader.h
More file actions
45 lines (39 loc) · 1 KB
/
loader.h
File metadata and controls
45 lines (39 loc) · 1 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
//
// Created by spring on 2025. 5. 11..
//
#ifndef LOADER_H
#define LOADER_H
#include <vector>
#include <string>
#include <fstream>
#include <sstream>
#include <stdexcept>
static std::vector<std::string> load_text(const std::string &filename) {
std::vector<std::string> texts;
std::ifstream fin(filename);
if (!fin) {
throw std::runtime_error("Could not open file " + filename);
}
std::string line;
while (std::getline(fin, line)) {
texts.push_back(line);
}
return texts;
}
static std::vector<std::vector<int> > load_gt(const std::string &filename) {
std::vector<std::vector<int> > gts;
std::ifstream fin(filename);
if (!fin) {
throw std::runtime_error("Could not open file " + filename);
}
std::string line;
while (std::getline(fin, line)) {
std::istringstream iss(line);
std::vector<int> row;
int x;
while (iss >> x) row.push_back(x);
gts.push_back(row);
}
return gts;
}
#endif //LOADER_H