container_device_example.cpp 942 B

123456789101112131415161718192021222324252627282930
  1. // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
  2. // (C) Copyright 2005-2007 Jonathan Turkanis
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
  5. // See http://www.boost.org/libs/iostreams for documentation.
  6. #include <cassert>
  7. #include <string>
  8. #include <boost/iostreams/stream.hpp>
  9. #include <boost/iostreams/detail/ios.hpp> // ios_base::beg.
  10. #include <libs/iostreams/example/container_device.hpp>
  11. namespace io = boost::iostreams;
  12. namespace ex = boost::iostreams::example;
  13. int main()
  14. {
  15. using namespace std;
  16. typedef ex::container_device<string> string_device;
  17. string one, two;
  18. io::stream<string_device> io(one);
  19. io << "Hello World!";
  20. io.flush();
  21. io.seekg(0, BOOST_IOS::beg);
  22. getline(io, two);
  23. assert(one == "Hello World!");
  24. assert(two == "Hello World!");
  25. }