How can I create an 'ostream' from a socket?

c++, sockets

Solution

The site you found is a third party non-standard library. There is no standard C++ socket library.

However, if you want as closest to a standard (and powerful!) solution, you should try Boost.Asio. It has been proposed for inclusion in the standard library (TR2). Here's an iostream based example:

boost::asio::ip::tcp::iostream stream("www.example.org", "http");
stream << "GET / HTTP/1.0\r\nHost: www.boost.org\r\n\r\n" << std::flush;

std::string response;
std::getline( stream, response );

However, you'd gain much more if using the Asio's Proactor for asynchronous operation.

Problem

In C++, if I have a socket, how can I create an ostream object from it? I have googled some example: http://members.aon.at/hstraub/linux/socket++/docu/socket++_10.html And I have tried: ``` sockbuf sb(sockfd); std::ostream outputStream(&sb); ``` But I can't find the .h file and the library to link with for 'sockbuf'. Is that part of a standard c++ library?

Original source