C++ program wont compile

Reply

Join Date: Feb 2009
Posts: 1
Reputation: nick2price is an unknown quantity at this point 
Solved Threads: 0
nick2price nick2price is offline Offline
Newbie Poster

C++ program wont compile

 
0
  #1
Feb 27th, 2009
I am not too sure about c++. I have this program so i can perform a test on it against java. It looks like
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <math.h>
  4. #include <sys/time.h>
  5.  
  6. using namespace std;
  7.  
  8. double generate(int max) {
  9. struct timeval start;
  10. struct timezone tz;
  11. gettimeofday(&start, &tz);
  12.  
  13. bool *sieve = new bool[max];
  14. for (int i=0; i<max; i++) sieve[i] = true;
  15. sieve[0] = false;
  16. sieve[1] = false;
  17. for (int n=2; n<sqrt(max); n++) {
  18. if (sieve[n]) {
  19. for (int j=2*n; j<max; j+=n)
  20. sieve[j] = false;
  21. }
  22. }
  23.  
  24. struct timeval end;
  25. gettimeofday(&end, &tz);
  26.  
  27. double startSecond = start.tv_usec/1000000.0;
  28. double endSecond = (end.tv_sec - start.tv_sec) + end.tv_usec/1000000.0;
  29. return endSecond - startSecond;
  30. }
  31.  
  32. int main(int argc, char * argv[])
  33. {
  34. for (int i=100000; i<=5000000; i+=100000) {
  35. double time = generate(i);
  36. cout << i << " " << time << "\n";
  37. }
  38. }

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?
thanks
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,815
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 213
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: C++ program wont compile

 
0
  #2
Feb 27th, 2009
try:
#include <cmath>
#include <ctime>
Don't own a gun but I'm going to join the NRA.
I figure anything that irritates liberals is worth my support.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 1,815
Reputation: vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold vmanes is a splendid one to behold 
Solved Threads: 213
vmanes's Avatar
vmanes vmanes is offline Offline
Posting Virtuoso

Re: C++ program wont compile

 
0
  #3
Feb 27th, 2009
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.
Don't own a gun but I'm going to join the NRA.
I figure anything that irritates liberals is worth my support.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 344
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: C++ program wont compile

 
0
  #4
Feb 27th, 2009
If you are trying to compile this Unix BSD-colored snippet on MS VC++ then have a look at
http://trac.osgeo.org/mapserver/ticket/602
May be it helps...
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 5
Reputation: Valkyriecoder is an unknown quantity at this point 
Solved Threads: 0
Valkyriecoder Valkyriecoder is offline Offline
Newbie Poster

Re: C++ program wont compile

 
0
  #5
Feb 27th, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 2,025
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 224
tux4life's Avatar
tux4life tux4life is offline Offline
Postaholic

Re: C++ program wont compile

 
0
  #6
Feb 28th, 2009
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)
Last edited by tux4life; Feb 28th, 2009 at 1:39 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 2,025
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 224
tux4life's Avatar
tux4life tux4life is offline Offline
Postaholic

Re: C++ program wont compile

 
0
  #7
Feb 28th, 2009
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...
Last edited by tux4life; Feb 28th, 2009 at 1:56 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 413 | Replies: 6
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC