summaryrefslogtreecommitdiff
path: root/2024/readfile.cpp
diff options
context:
space:
mode:
Diffstat (limited to '2024/readfile.cpp')
-rw-r--r--2024/readfile.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/2024/readfile.cpp b/2024/readfile.cpp
new file mode 100644
index 0000000..eb05812
--- /dev/null
+++ b/2024/readfile.cpp
@@ -0,0 +1,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;
+}