我使用一些代码来报告任务的持续时间,使用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
解决方法
对于eclipse中的计时器,您应该添加这些符号
_GLIBCXX_USE_C99_STDINT_TR1
和
__cplusplus = 201103L
如何添加它们:
投影属性 – > C/C++一般 – >路径和符号 – >符号(Tab) – > GNU C – >并点击添加.
记得添加__cplusplus值为201103L
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。