标签:style io ar os 使用 sp 数据 on div
Boost.Asio-其他特性
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();
标签:style io ar os 使用 sp 数据 on div
原文地址:http://www.cnblogs.com/yuyanbian/p/4107245.html