Boost logo

Boost :

From: Stefan Hojer (redcube_at_[hidden])
Date: 2002-08-29 06:33:38


Hi,

Is it possible to parse a file directly from disc, without reading its
contents line by line or in blocks?

I tried the following code:

////////////////////////
using namespace boost;
using namespace std;

ifstream file("test.conf", ios::in);
typedef tokenizer<my_separator, istream_iterator<char> > parser_type;
parser_type parser(istream_iterator<char>(file),
                   istream_iterator<char>());

for (parser_type::iterator i=parser.begin(); i != parser.end(); ++i)
     cout << '\'' << *i << '\'' << endl;
////////////////////////

The my_separator-Class works fine when using it with "std::string::iterator"
instead of "istream_iterator<char>".

If i try to compile the above code, i will get the following error messages
in GCC 3.1 (i686-pc-linux-gnu):

////////////////////////
test.cpp:1015: request for member `begin' in `
   parser(std::istream_iterator<char, char, std::char_traits<char>,
ptrdiff_t>,
   std::istream_iterator<char, char, std::char_traits<char>, ptrdiff_t>
(*)())
   ', which is of non-aggregate type `main()::parser_type
   ()(std::istream_iterator<char, char, std::char_traits<char>, ptrdiff_t>,
   std::istream_iterator<char, char, std::char_traits<char>, ptrdiff_t>
(*)())'
test.cpp:1015: request for member `end' in
`parser(std::istream_iterator<char,
   char, std::char_traits<char>, ptrdiff_t>, std::istream_iterator<char,
char,
   std::char_traits<char>, ptrdiff_t> (*)())', which is of non-aggregate
type `
   main()::parser_type ()(std::istream_iterator<char, char,
   std::char_traits<char>, ptrdiff_t>, std::istream_iterator<char, char,
   std::char_traits<char>, ptrdiff_t> (*)())'
////////////////////////

Line 1015 is the for-loop.

Does anyone have an idea how I can handle this problem? (Without reading the
file blockwise or line-by-line into a string object)

--
Greetz, Stefan Hojer

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk