繁体   English   中英

“ cout&endl”和“ boost”有什么问题?

[英]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

然后我尝试将coutendl更改为std::coutstd::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;

和其他coutendl

在文件顶部将#include <iostream>绑定。

基本的东西真的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM