2

I want use clock function in my program so I am referring to how to use clock().

My code :

#include <iostream>
#include <cstdio>
#include <ctime>

int main() {
    std::clock_t start;
    //clock_t start;  
    double duration;

    start = std::clock();
    //start = clock(); //This Also not working

    /* Your algorithm here */

    duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC;
    //duration = ( clock() - start ) / (double) CLOCKS_PER_SEC;

    std::cout<<"printf: "<< duration <<'\n';
}

But still I am having compilation errors

error C2039: 'clock' : is not a member of '`global namespace'' ....\ctime
error C2873: 'clock' : symbol cannot be used in a using-declaration ....\ctime
error C3861: 'clock': identifier not found ....\main.cpp

So I have checked ctime header file by opening in visual studio in that also

using _CSTD asctime; using _CSTD clock; using _CSTD ctime;

for this line it's gives an error

Error: the global scope has no "clock"

Please help me to solve these errors?

Community
  • 1
  • 1
Mohan
  • 1,871
  • 21
  • 34

1 Answers1

0

I have looked into my program include path. I have seen there are two location where time.h is present.

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include

Replaced time.h file of path C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include which was referring my program by coping from another location.

Mohan
  • 1,871
  • 21
  • 34