I am not too sure about c++. I have this program so i can perform a test on it against java. It looks like

#include "stdafx.h"
#include <iostream>   
#include <math.h>   
#include <sys/time.h>   
using namespace std;   
double generate(int max) {   
  struct timeval start;   
  struct timezone tz;   
  gettimeofday(&start, &tz);   
  bool *sieve = new bool[max];   
  for (int i=0; i<max; i++) sieve[i] = true;   
  sieve[0] = false;   
  sieve[1] = false;   
  for (int n=2; n<sqrt(max); n++) {   
    if (sieve[n]) {   
      for (int j=2*n; j<max; j+=n)   
        sieve[j] = false;   
  struct timeval end;   
  gettimeofday(&end, &tz);   
  double startSecond = start.tv_usec/1000000.0;   
  double endSecond = (end.tv_sec - start.tv_sec) + end.tv_usec/1000000.0;   
  return endSecond - startSecond;   
int main(int argc, char * argv[])   
  for (int i=100000; i<=5000000; i+=100000) {   
    double time = generate(i);   
    cout << i << " " << time << "\n";   

It says at the moment that
1>c:\users\nick\desktop\dd\dd\dd.cpp(4) : fatal error C1083: Cannot open include file: 'sys/time.h': No such file or directory

How would i go about resolving this issue?

Recommended Answers

All 6 Replies

#include <cmath>
#include <ctime>

Oops, never mind. It would appear that you're using a compiler that doesn't support that functionality. VC++ doesn't seem to have it.

its because you have to have the header file named time.... time.h is a header file basicly it means that there must be a extra file your missing.... and what IDE/compiler are you using?

Hmm, seems like it can't find the file 'sys/time.h'

What IDE and compiler are you using?

(With me this program just compiles/runs perfectly, I'm using the latest MinGW compiler together with the latest Code::Blocks IDE)

I guess he's using a Microsoft compiler, maybe you should try: '#include <time.h>' instead...
Or maybe you should use MinGW to compile this code snippet, as you said it's only for a test...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.