fork download
  1. static std::vector<char> readFile(const char* filename)
  2. {
  3. std::ifstream file;
  4. file.open(filename, std::ios::in);
  5. if(!file.good())
  6. throw std::runtime_error("Cannot open input file.");
  7.  
  8. file >> std::noskipws;
  9. file.exceptions(std::ios::failbit | std::ios::badbit);
  10. try
  11. {
  12. std::vector<char> result;
  13. std::copy(std::istream_iterator<char>(file), std::istream_iterator<char>(), std::back_inserter(result));
  14. return result;
  15. }
  16. catch(std::ios_base::failure& e)
  17. {
  18. throw std::runtime_error("I/O error when reading the input file.");
  19. }
  20. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty