istreambuf_iterator STL question
Nov 29, 2012 at 11:15am UTC
hi everybody . please help me
1 2 3 4 5
freopen("in.txt" , "r" , stdin);
deque<char > dq;
copy(istreambuf_iterator<char >(cin), istreambuf_iterator<char >(),
back_inserter(dq));
and in.txt is :
95.123 12
0.43 20
5.1234 10
6.759 25
98.999 2
1.0 3
i want change this code read until ' ' charactor ! for example in first copy function dq become 95.123 . sorry for my bad eng language !
note : i want dq be char because it be big number !
Last edited on Nov 29, 2012 at 11:16am UTC
Nov 29, 2012 at 2:48pm UTC
Normally you would use
getline(stream, string, ' ' )
for that, or some other stream parsing method.
But you could do with input iterators of course, as long as your algorithm is single-pass:
1 2 3 4 5 6
ifstream fin("in.txt" ); // why freopen?
deque<char > dq;
istreambuf_iterator<char > i(fin), end;
while (i != end && *i != ' ' )
dq.push_back(*i++);
Nov 29, 2012 at 7:28pm UTC
my dear i want use copy function !! i think i must define my char_traits and change eof type and send it to template argument of istreambuf_iterator
Topic archived. No new replies allowed.