I am writing a game in which I need to know whether or not a user preforms an action in one second or less. I can not use time() because it measures time in seconds. If the user starts the action half-way through a second it would mess with accuracy. I am experimenting with clock(). I have got clock to work with some programs to make a delay, but not in this way to measure time: [CODE] #include <iostream> #include <ctime> using namespace std; int main() { clock_t start = clock(); cout << "press enter..."; cin.ignore(); clock_t finish = clock(); …

Member Avatar
Member Avatar
+0 forum 12

The function i am writing below is made to time how long it takes to process a function. // return type for func(pointer to func)(parameters for func), container eg.vector clock_t timeFuction(double(*f)(vector<double>), vector<double> v) { auto start = clock(); f(v); return clock() - start; } This is the function i want to test in my timeFunction. template<typename T> double standardDeviation(T v) { auto tempMean = mean(v); //declared else where double sq_sum = inner_product(v.begin(), v.end(), v.begin(), 0.0); double stdev = sqrt(sq_sum / v.size() - tempMean * tempMean); return stdev; } standardDiviation was made with a template so it can accept any c++ …

Member Avatar
Member Avatar
+0 forum 2

Howdy, I have a few questions regarding the use of ctime within a class. I followed the example on [URL="http://www.cplusplus.com/reference/clibrary/ctime/strftime/"]http://www.cplusplus.com/reference/clibrary/ctime/strftime/[/URL] When the program is like this, it works: [CODE] #include <ctime> #include <iostream> using namespace std; int main(){ time_t current_seconds; current_seconds = time(NULL); //Fills current_seconds with the number of seconds since January 1, 1970 struct tm * timeinfo; char buffer [80]; time (&current_seconds); timeinfo = localtime (&current_seconds); strftime (buffer,80,"Event Date: %x",timeinfo); //Modifies timeinfo into a user readable format puts(buffer); // Posts the string "buffer" strftime (buffer,80,"Event Time: %X %Z",timeinfo); puts(buffer); return 0; } [/CODE] [B]Question 1[/B]: Is it possible to …

Member Avatar
Member Avatar
+0 forum 3

Hi, I have a csv datafile with stock price data that I've read into a vector of structures that looks like this: 09/11/2009 9.30 open, high, low, close, volume 09/11/2009 9.31 o, h, l, c, volume and so on to 09/11/2009 16.14 o, h, l, c, volume //next day starts here: 09/12/2009 9.30, o, h, l, c, volume 09/12/2009 9.31, o, h, l, c, volume As you can see, each date has ~390 minutes of price data associated with it. I would like to be able to compare these dates, but the date field is of type string. How do …

Member Avatar
Member Avatar
+0 forum 4

Hi all! I am trying to manage and understand dates with c++, but the output that I am having does not help much. Basically I would like to adjust a localtime that can be seen in the string "s_prueba_time" to a UTC time (in my case -2 hours in summer and -1 in winter). But the output I am having from executing this program is completely weird! Here you have! ??? Mar 30 06:57:57 2010 Tue Mar 30 07:57:57 2010 Local time and date: Tue Mar 30 05:57:57 2010 UTC time and date: Tue Mar 30 03:57:57 2010 The difference …

Member Avatar
Member Avatar
+0 forum 2

The End.