SSAGES  0.9.3
Software Suite for Advanced General Ensemble Simulations
FileContents.h
Go to the documentation of this file.
1 
26 #pragma once
27 
28 #include <fstream>
29 #include <string>
30 
36 namespace SSAGES
37 {
39 
46  inline std::string GetFileContents(const std::string filename)
47  {
48  std::ifstream ifs(filename);
49  if(ifs.is_open()) {
50  std::string contents( (std::istreambuf_iterator<char>(ifs) ),
51  (std::istreambuf_iterator<char>() ) );
52  return contents;
53  }
54  throw std::runtime_error("File " + filename + " does not exist.");
55  }
56 
58 
62  inline std::string GetFilePath(const std::string filename)
63  {
64  size_t found;
65  found = filename.find_last_of("/\\");
66  if(found == filename.npos)
67  return "./";
68  return filename.substr(0, found);
69  }
70 }
std::string GetFileContents(const std::string filename)
Read contents from a file.
Definition: FileContents.h:46
std::string GetFilePath(const std::string filename)
Gets file path from filename.
Definition: FileContents.h:62