class template
<iterator>
std::ostreambuf_iteratortemplate <class charT, class traits=char_traits<charT> > class ostreambuf_iterator;
Output stream buffer iterator
They are constructed from a basic_streambuf object open for writing, to which they become associated.
It is defined with a behavior similar to:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
template <class charT=char, class traits=char_traits<charT> >
class ostreambuf_iterator :
public iterator<output_iterator_tag, charT,
typename traits::off_type, charT*, charT&>
{
public:
typedef charT char_type;
typedef traits traits_type;
typedef typename traits::int_type int_type;
typedef basic_streambuf<charT,traits> streambuf_type;
typedef basic_ostream<charT,traits> ostream_type;
ostreambuf_iterator(ostream_type& s) throw(): sbuf_(s.rdbuf()) { }
ostreambuf_iterator(streambuf_type* s) throw(): sbuf_(s) { }
ostreambuf_iterator& operator= (charT c)
{ if (!failed()) last=sbuf_->sputc(c); return *this; }
ostreambuf_iterator& operator*() { return *this; }
ostreambuf_iterator& operator++() { return *this; }
ostreambuf_iterator& operator++(int) { return *this;}
bool failed() const throw() { return last==traits::eof(); }
private:
streambuf_type* sbuf_;
charT last;
};
operator=
operator*
operator++
*this
.
operator++(int)
*this
.
traits::eof()
in a previous call to operator=
).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// ostreambuf_iterator example
#include <iostream> // std::cin, std::cout
#include <iterator> // std::ostreambuf_iterator
#include <string> // std::string
#include <algorithm> // std::copy
int main () {
std::string mystring ("Some text here...\n");
std::ostreambuf_iterator<char> out_it (std::cout); // stdout iterator
std::copy ( mystring.begin(), mystring.end(), out_it);
return 0;
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4