标签:
size_t read_complete(boost::system::error_code, size_t bytes){ ... }
char buff[1024];
read(sock, buffer(buff), read_complete);
write(sock, buffer("echo\n"));
streambuf buf;
read(sock, buf);
streambuf buf;
read_until(sock, buf, "\n");
streambuf buf;
std::ostream out(&buf);
out << "echo" << std::endl;
write(sock, buf);
struct person {
std::string first_name, last_name;
int age;
};
std::ostream& operator<<(std::ostream & out, const person & p) {
return out << p.first_name << " " << p.last_name << " " << p.age;
}
std::istream& operator>>(std::istream & in, person & p) {
return in >> p.first_name >> p.last_name >> p.age;
}
streambuf buf;
std::ostream out(&buf);
person p;
// … 初始化p
out << p << std::endl;
write(sock, buf);
read_until(sock, buf, "\n");
std::istream in(&buf);
person p;
in >> p;
当使用<<操作符时这些操作默认都已经做了
streambuf buf;
...
std::cout << &buf << std::endl; // 把全部内容输出到console中
std::string to_string(streambuf &buf) {
std::ostringstream out;
out << &buf;
return out.str();
}
标签:
原文地址:http://www.cnblogs.com/bhlsheji/p/4878046.html