Rob*_*mer 11 c++ eclipse boost c++11
我使用一些代码来报告任务的持续时间使用std :: chrono :: high_resolution_clock ... c ++ 0x的一部分.
我可以使用-gnu ++ 0x标志在eclipse cdt中成功编译c ++ 0x特性.虽然成功编译,编辑器似乎没有意识到c ++ 0x,即它在我的代码中显示任何c ++ 0x特性的错误.我通过在项目发现选项中添加-gnu ++ 0x标志来解决这个问题.注意:在您执行另一次编译并重建索引之前,不显示已修复...
-E -P -v -dD"$ {plugin_state_location} /specs.cpp"-std = gnu ++ 0x
我仍然有一个最后一个编辑器错误,我无法摆脱"符号'duration_cast'无法解决"(我有一张照片,但新用户无法发布照片)
任何人都有任何想法如何解决这个问题?这是代码:
#ifndef _scoped_timer_h_
#define _scoped_timer_h_
#include <iostream>
#include <chrono>
#include "boost/noncopyable.hpp"
#include "boost/format.hpp"
using namespace std::chrono;
// Utility class for timing and logging rates
// (ie "things-per-second").
// NB _any_ destructor invokation (including early return
// from a function or exception throw) will trigger an
// output which will assume that whatever is being measured
// has completed successfully and fully.
class scoped_timer : boost::noncopyable
{
public:
scoped_timer(
const std::string& what,
const std::string& units,
double n
)
:_what(what)
,_units(units)
,_how_many(n)
,_start(high_resolution_clock::now())
{}
~scoped_timer() {
high_resolution_clock::time_point stop = high_resolution_clock::now();
const double t = 1e-9 * duration_cast<nanoseconds>(stop-_start).count();
std::cout << (
boost::format(
"%1%: %|2$-5.3g| %|3$|/s (%|4$-5.3g|s)"
) % _what % (_how_many/t) % _units % t
) << std::endl;
}
private:
const std::string _what;
const std::string _units;
const double _how_many;
const high_resolution_clock::time_point _start;
};
#endif
Run Code Online (Sandbox Code Playgroud)
对于日食中的计时器,你应该添加这些符号
_GLIBCXX_USE_C99_STDINT_TR1
Run Code Online (Sandbox Code Playgroud)
和
__cplusplus = 201103L
Run Code Online (Sandbox Code Playgroud)
如何添加它们:
Prject properties - > C/C++ General - > Path and Symbols - > Symbols(Tab) - > GNU C++ - >点击添加.
记得添加__cplusplus
有价值的东西201103L
归档时间: |
|
查看次数: |
5821 次 |
最近记录: |