为什么我不能在代码块 12.11 编译器中使用clock_t?

why can't I use clock_t in codeblocks 12.11 compiler?

本文关键字:clock 编译器 不能 代码 为什么      更新时间:2023-10-16

我正试图在代码块中编译代码,但它显示了一些错误。
我的代码是:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<iostream>
using namespace std;
void f()
{
   int sum=0;
   for(int i=0;i<100000000;i++)
       sum++;
}
int main()
{
   clock_t start,end;
   start=clock();
   f();
   end=clock();
   cout<<((double)end-start)/CLOCKS_PER_SEC<<endl;
}  

但是显示了一些错误,错误是这样的:
" #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options."
我现在该怎么办呢?

根据错误提示,只需启用c++ 11特性即可。要这样做(感谢@chris的评论):

就在设置里。就像字面上的一个选项说"使用c++ 11标准"。