-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCommon.h
More file actions
37 lines (32 loc) · 800 Bytes
/
Copy pathCommon.h
File metadata and controls
37 lines (32 loc) · 800 Bytes
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
#pragma once
#include <fstream>
#include <sstream>
#include <stdexcept>
#include <string>
#include <string_view>
#include <vector>
namespace Common
{
inline std::vector<std::string> ReadFile(const char* filename) {
std::ifstream inputFile{};
inputFile.open(filename);
if (!inputFile.is_open()) {
throw std::runtime_error("File not found");
}
std::vector<std::string> out;
std::string buffer;
while (std::getline(inputFile, buffer)) {
out.push_back(buffer);
}
return out;
}
[[nodiscard]] inline std::vector<std::string> Split(const std::string& s, char delimiter) {
std::vector<std::string> tokens;
std::string token;
std::istringstream tokenStream(s);
while (std::getline(tokenStream, token, delimiter)) {
tokens.push_back(token);
}
return tokens;
}
}