[英]what's wrong with the “cout&endl” and the “boost”?
这是我第一次在计算机上使用boost-Ubuntu 12.04 amd64(带有g ++ 4.6.3)。 以下是来源:
#include <boost/timer.hpp>
using namespace boost;
int main()
{
timer t;
cout << "max timespan: "
<< t.elapsed_max() / 3600 << "h" << endl;
cout << "min timespan: "
<< t.elapsed_min() << "s" << endl;
cout << "now time elapsed:"
<< t.elapsed() << "s" << endl;
return 0;
}
但是,当我使用g++ timer_test.c -o timer_test
编译时,会出现奇怪的错误:
timer_test.cpp: In function ‘int main()’:
timer_test.cpp:9:3: error: ‘cout’ was not declared in this scope
timer_test.cpp:10:44: error: ‘endl’ was not declared in this scope
然后我尝试将cout
和endl
更改为std::cout
和std::endl
,错误变为:
error: ‘cout’ is not a member of ‘std’
error: ‘endl’ is not a member of ‘std’
您需要包括iostream
标头,并使用std::cout and std::endl
因为它们是在std
名称空间中定义的。
#include <iostream>
std::cout << "max timespan: "
<< t.elapsed_max() / 3600 << "h" << std::endl;
和其他cout
, endl
在文件顶部将#include <iostream>
绑定。
基本的东西真的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.