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
7#include <iostream>
8#include <fstream>
9#include <string>
10
11///////////////////////////////////////////////////////////////////////////////
12// Helper function reading a file into a string
13///////////////////////////////////////////////////////////////////////////////
14inline std::string
15read_from_file(char const* infile)
16{
17 std::ifstream instream(infile);
18 if (!instream.is_open()) {
19 std::cerr << "Couldn't open file: " << infile << std::endl;
20 exit(status: -1);
21 }
22 instream.unsetf(mask: std::ios::skipws); // No white space skipping!
23 return std::string(std::istreambuf_iterator<char>(instream.rdbuf()),
24 std::istreambuf_iterator<char>());
25}
26
27

source code of boost/libs/spirit/example/lex/example.hpp