Guest User

Untitled

a guest
Jun 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.97 KB | None | 0 0
  1. std::string operator , (const std::string& s1, const char* s2)
  2. {
  3.   return s1 + s2;
  4. }
  5.  
  6. std::string operator , (const char* s1, const std::string& s2)
  7. {
  8.   return s1 + s2;
  9. }
  10.  
  11. #define TO_STRING_I(n) #n
  12. #define TO_STRING(n) TO_STRING_I(n)
  13. #define FILEPOS __FILE__ "(" TO_STRING(__LINE__) "): "
  14. #define THROW_IF(cond, type, msg, ...) if (cond) throw type((FILEPOS + std::string(msg), __VA_ARGS__).c_str())
  15.  
  16. struct fatal_error : public std::runtime_error
  17. {
  18.     fatal_error(const char* errormsg)
  19.         : std::runtime_error(errormsg)
  20.     {}
  21. };
  22.  
  23. inline std::vector<char> read_file(const char* filename)
  24. {
  25.     std::ifstream file(filename, std::ios::binary);
  26.   THROW_IF(!file, fatal_error, "Could not open file: ", filename);
  27.   file.seekg(0, std::ios::end);
  28.     std::vector<char> buf(static_cast<std::vector<char>::size_type>(file.tellg()));
  29.     file.seekg(0, std::ios::beg);
  30.   file.read(&buf[0], buf.size());
  31.   THROW_IF(!file, fatal_error, "Could not read file: ", filename);
  32.   return buf;
  33. }
Add Comment
Please, Sign In to add comment