这是我第一次在我的机器上使用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’
答案 0 :(得分:3)
您需要包含iostream
标头并使用std::cout and std::endl
,因为它们是在std
命名空间中定义的。
#include <iostream>
std::cout << "max timespan: "
<< t.elapsed_max() / 3600 << "h" << std::endl;
与其他cout
,endl
答案 1 :(得分:1)
在文件顶部的#include <iostream>
中插入。
基本的东西真的