read_line.hpp
Go to the documentation of this file.
1 #ifndef STAN_IO_READ_LINE_HPP
2 #define STAN_IO_READ_LINE_HPP
3 
4 #include <istream>
5 #include <sstream>
6 #include <string>
7 
8 namespace stan {
9  namespace io {
10 
11  /**
12  * Returns the next line read from the specified stream, or the
13  * empty string if the stream is empty.
14  *
15  * <p>The input stream is read character by character and not
16  * buffered, though the use cases are only for small files of
17  * code, so this probably isn't a big deal.
18  *
19  * @param in input stream
20  * @return next line from stream or empty string if empty
21  */
22  inline std::string read_line(std::istream& in) {
23  std::stringstream ss;
24  while (true) {
25  int c = in.get();
26  if (c == std::char_traits<char>::eof())
27  return ss.str();
28  ss << static_cast<char>(c);
29  if (c == '\n')
30  return ss.str();
31  }
32  }
33 
34  }
35 }
36 #endif
std::string read_line(std::istream &in)
Definition: read_line.hpp:22
Float_t ss
Definition: plot.C:24
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
ifstream in
Definition: comparison.C:7