为什么下面的代码会输出“Unknown error”?我期待一些其他消息,例如“操作超时”或其他描述性错误。
操作系统:Windows 7 boost :1.57
#include <iostream>
#include "boost/system/system_error.hpp"
void main()
{
boost::system::error_code ec = make_error_code(boost::system::errc::timed_out);
auto message = ec.message();
std::cout << message << std::endl;
}
建议您检查包含路径、库路径和项目设置。
我已经更正了程序(main 必须返回一个 int)并在 clang 下编译:
#include <iostream>
#include <boost/system/system_error.hpp>
int main()
{
boost::system::error_code ec = make_error_code(boost::system::errc::timed_out);
auto message = ec.message();
std::cout << message << std::endl;
}
命令行:
c++ -std=c++14 -I${HOME}/local/include -L${HOME}/local/lib -lboost_system
结果:
Operation timed out
我的boost安装安装到前缀${HOME}/local
我是一名优秀的程序员,十分优秀!