Thread: help with getting drand48() to work

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    26

    help with getting drand48() to work

    Code:
    #include <iostream>
    #include <ctime>
    #include <stdio.h>
    #include <stdlib.h>
    #include "PQ.h"
    
    using namespace std;
    
    int main()
    {
    	PQ my_jobs;			//PriorityQueue object 
    	int x;
    	int a;
    	cout<<drand48()<<endl;
    	return 0;
    	for(x=0; x<10000; x++)
    	{
    		a = (rand() % 65535);
    		my_jobs.insert(0,a);
    	}
    	my_jobs.queueStatus();
       
    	return 0;
    }
    I am using microsoft visual studio c++ and get the following compile time errors with drand48:
    main.cpp(14): error C2065: 'drand48' : undeclared identifier
    main.cpp(14): error C2593: 'operator <<' is ambiguous

    any ideas on how i can fix this?

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    What's drand48() supposed to do? I think you have to be on a unix machine to use that.

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    To the best of my knowledge, that is not a standard function in terms of Microsoft's libraries. What do you need it for?

    Some points:

    1) As you have it, your code will never get beyond that first return statement, i.e. it will never reach the for loop. Is that just for testing purposes?

    2) The stdlib.h and stdio.h headers are deprecated, you should have instead used cstdlib and cstdio.

    3) The STL already defines a priority_queue object, include the queue header to use it.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    26
    the first return statement is for testing purposes i just want to get the drand48 function to work. also i am using my own priority queue "PQ.h". I want to be able to use drand48 with visual studio because otherwise i have to log into a unix terminal at school and working on that is annoying. If there is any way to get drand48 to work that would be appreciated.

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Is there any reason you can't use rand() instead?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  2. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  3. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 04:48 AM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM