summaryrefslogtreecommitdiff
path: root/2024/readfile.cpp
blob: eb05812cd0d05c609ab49d9624c8eff395480e91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <fstream>
#include <vector>
#include "readfile.hpp"

std::vector<std::string> readfile(const std::string &name) {
    std::vector<std::string> file;
	std::ifstream f(name);

    if (!f) {
        std::cerr << "Error: Unable to open file" << std::endl;
        return {};
    }

	std::string line;
	while (getline(f, line)) {
		file.push_back(line);
	}

	f.close();
	return file;
}