| 1 | #include "grep.hpp"
|
|---|
| 2 |
|
|---|
| 3 | #include <boost/iostreams/device/file.hpp>
|
|---|
| 4 | #include <boost/iostreams/filtering_stream.hpp>
|
|---|
| 5 | #include <iostream>
|
|---|
| 6 |
|
|---|
| 7 | int main()
|
|---|
| 8 | {
|
|---|
| 9 | boost::iostreams::grep_filter filter("main");
|
|---|
| 10 |
|
|---|
| 11 | {
|
|---|
| 12 | boost::iostreams::filtering_istream is;
|
|---|
| 13 |
|
|---|
| 14 | is.unsetf(std::ios::skipws);
|
|---|
| 15 | is.push(filter);
|
|---|
| 16 | is.push(boost::iostreams::file_source("main.cpp"));
|
|---|
| 17 |
|
|---|
| 18 | std::copy(std::istream_iterator<char>(is),
|
|---|
| 19 | std::istream_iterator<char>(),
|
|---|
| 20 | std::ostream_iterator<char>(std::cout));
|
|---|
| 21 |
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | {
|
|---|
| 25 | boost::iostreams::filtering_ostream os;
|
|---|
| 26 |
|
|---|
| 27 | os.push(filter);
|
|---|
| 28 | os.push(boost::iostreams::file_sink("test.txt"));
|
|---|
| 29 |
|
|---|
| 30 | std::ifstream f("main.cpp");
|
|---|
| 31 | f.unsetf(std::ios::skipws);
|
|---|
| 32 |
|
|---|
| 33 | std::copy(std::istream_iterator<char>(f),
|
|---|
| 34 | std::istream_iterator<char>(),
|
|---|
| 35 | std::ostream_iterator<char>(os));
|
|---|
| 36 | }
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|