Skip to content

Instantly share code, notes, and snippets.

@ar1a
Created May 15, 2016 05:57
Show Gist options
  • Save ar1a/f2d4c53f8d8b40c9acf73b577acb5f2b to your computer and use it in GitHub Desktop.
Save ar1a/f2d4c53f8d8b40c9acf73b577acb5f2b to your computer and use it in GitHub Desktop.
ifstream wrapper to return an array of strings for each line
#pragma once
#include <vector>
#include <string>
#include <fstream>
class Text_file
{
public:
Text_file() : strings() {}
Text_file(const std::string& file_name) : strings()
{
load_file(file_name);
}
Text_file& load_file(const std::string& file_name)
{
std::ifstream file{ file_name };
std::string temp;
while (std::getline(file, temp)) {
strings.push_back(temp);
}
return *this;
}
std::vector<std::string> get_file()
{
return strings;
}
Text_file& clean()
{
strings.clear();
return *this;
}
private:
std::vector<std::string> strings;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment