example.hpp 936 B

1234567891011121314151617181920212223242526
  1. // Copyright (c) 2001-2010 Hartmut Kaiser
  2. // Copyright (c) 2001-2007 Joel de Guzman
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #include <iostream>
  7. #include <fstream>
  8. #include <string>
  9. ///////////////////////////////////////////////////////////////////////////////
  10. // Helper function reading a file into a string
  11. ///////////////////////////////////////////////////////////////////////////////
  12. inline std::string
  13. read_from_file(char const* infile)
  14. {
  15. std::ifstream instream(infile);
  16. if (!instream.is_open()) {
  17. std::cerr << "Couldn't open file: " << infile << std::endl;
  18. exit(-1);
  19. }
  20. instream.unsetf(std::ios::skipws); // No white space skipping!
  21. return std::string(std::istreambuf_iterator<char>(instream.rdbuf()),
  22. std::istreambuf_iterator<char>());
  23. }