我正在尝试编译一个MWE,取自boost tutorials。
奇怪的是,我的编译器抱怨tcp::iostream
没有方法error():
error: ‘boost::asio::ip::tcp::iostream’ has no member named ‘error’
我很确定我的包含设置没问题,因为它找到了头文件。
此外,error()
方法在boost API中似乎相对较长时间。我提到这个,因为我正在尝试使用Point Cloud Library。通过安装此库,我还安装了boost,它可能是旧版本。我不知道要检查版本,但正如我所说,我认为这不是问题。
有什么建议吗?
#include <iostream>
#include <string>
#include <boost/asio.hpp>
using boost::asio::ip::tcp;
int main(int argc, char* argv[]) {
try {
if (argc != 2) {
std::cerr << "Usage: daytime_client <host>" << std::endl;
return 1;
}
tcp::iostream s(argv[1], "daytime");
if (!s) {
std::cout << "Unable to connect: " << s.error().message() << std::endl;
return 1;
}
std::string line;
std::getline(s, line);
std::cout << line << std::endl;
} catch (std::exception& e) {
std::cout << "Exception: " << e.what() << std::endl;
}
return 0;
}