Boost logo

Boost :

From: John Ky (newhoggy_at_[hidden])
Date: 2007-07-19 01:52:36


Hi Boost,

I have narrow stream buffers in the form:

  asio::streambuf request;
  asio::streambuf response;

I currently read and write to them via narrow streams:

    std::istream request_stream(&request);
    std::ostream response_stream(&response);

I also have a function foo with wide character stream operators:

  std::wostream &operater<<(std::wostream &, const foo &);
  std::wistream &operater>>(std::wistream &, foo &);

I need a way to adapt my narrow request_stream and response_stream into wide
streams so that I can use my foo class stream operators.

I'm found the code_converter class which appears to do what I want but
examples are hard to come by.

I got something compiling, but I don't know if it is correct:

  typedef boost::iostreams::code_converter<
      boost::iostreams::array_source,
      std::codecvt<wchar_t, char, mbstate_t> > char_to_wchar;

  boost::iostreams::stream<char_to_wchar> request_stream(&request_);

  request_stream >> foo_object;

I also don't know how to do the reverse as the following doesn't compile at
all:

  boost::iostreams::stream<char_to_wchar> response_stream(&response_);

  response_stream << foo_object;

Anyone got any advice on this?

Thanks

-John


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk