Re: std::istreambuf_iterator
On Aug 11, 11:51 pm, "BobR" <removeBadB...@worldnet.att.net> wrote:
James Kanze <james.ka...@gmail.com> wrote in message...
On Aug 11, 6:16 pm, "BobR" <removeBadB...@worldnet.att.net> wrote:
James Kanze <james.ka...@gmail.com> wrote in message...
std::vector< std::string > data(
(std::istreambuf_iterator< std::string >( inputFile )),
(std::istreambuf_iterator< std::string >()) ) ;
(Formally, it's sufficient to add the parentheses to just one of
the arguments, but I like orthogonality.)
Did that compile for you ( using std::string in
istreambuf_iterator!! )? (which compiler?)
You're right, I didn't try it:-). You'd need
std::istream_iterator for std::string.
Don't know what I was thinking of.
Probably that thread a while back. But, that was using type 'char'.
Not really. I was basing my response on the original posting,
plus the error message he got. The error message was due to his
declaring a function, not a variable. (And of course, declaring
std::istreambuf_iterator< std::string > as a parameter of a
function probably won't cause any errors from the compiler,
since using a class template as a function parameter in a
declaration doesn't trigger instantiation.)
// ref: std::ifstream PicIn( ...., '::in | '::binary );
std::vector<unsigned char> Image(
std::istreambuf_iterator<char>( PicIn.rdbuf() ),
std::istreambuf_iterator<char>()
);
The code you showed was the *first* thing I tried. <G>
Which, of course, would generate a different error message than
the one he got. So he really had two problems. The data
definition which is really a function declaration is so common
that I didn't think further, but that's not really an excuse for
posting an answer without having actually tried it. (Formally,
std::istreambuf_iterator< std::string > is undefined behavior,
so you're not guaranteed a compiler error. But I'd be very
surprised if you didn't get one if you actually tried to use it.
--
James Kanze (GABI Software) email:james.ka...@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34