diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2024-12-01 20:27:19 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2024-12-01 20:27:19 +0800 |
| commit | af9b4431f36a28a0b52bc2a313e1d8ba98bc47d8 (patch) | |
| tree | 928b212664b8fc85f675740a9e432bdcdfe945ac /2024/readfile.cpp | |
| parent | 4f9b62dbf6e8d2df2616c28d147e3e522728f488 (diff) | |
init: 2024
Diffstat (limited to '2024/readfile.cpp')
| -rw-r--r-- | 2024/readfile.cpp | 22 |
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; +} |
