Created
May 15, 2016 05:57
-
-
Save ar1a/f2d4c53f8d8b40c9acf73b577acb5f2b to your computer and use it in GitHub Desktop.
ifstream wrapper to return an array of strings for each line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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