OGS
readStringListFromFile.cpp
Go to the documentation of this file.
1 
11 
12 #include <fstream>
13 
14 #include "BaseLib/Logging.h"
15 #include "BaseLib/StringTools.h"
16 
17 namespace BaseLib
18 {
19 namespace IO
20 {
21 std::vector<std::string> readStringListFromFile(std::string const& filename)
22 {
23  std::vector<std::string> string_list;
24  std::ifstream in(filename);
25  if (!in)
26  {
27  ERR("Could not open file {:s}.", filename);
28  return string_list;
29  }
30  std::string line;
31  while (std::getline(in, line))
32  {
33  trim(line);
34  if (line.empty())
35  {
36  continue;
37  }
38  string_list.push_back(line);
39  }
40  return string_list;
41 }
42 } // namespace IO
43 } // namespace BaseLib
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
Definition of string helper functions.
std::vector< std::string > readStringListFromFile(std::string const &filename)
Reads non-empty lines from a list of strings from a file into a vector.
void trim(std::string &str, char ch)
Definition: StringTools.cpp:58