Conversion of C++ code from Linux to Windows

前端 未结 3 1852

I am new to C++ , I have a program in C++ written for Linux. I\'m trying to convert it to Windows. The code I have is:

struct Timer 
{  
    struct tms t[2];
            


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-21 00:46

    Here is a drop-in replacement that returns the user time, rather than the elapsed time:

    #include 
    
    struct Timer 
    {  
        ULONGLONG t[2];
    
        void STARTTIME (void)
        {
            t[0] = getCurrentUserTime();
        }
    
        void  STOPTIME(void)
        {
            t[1] = getCurrentUserTime();
        }
    
        double USERTIME(void)
        {
            return (t[1] - t[0]) / 1e7; 
        }
    
    private:
        // Return current user time in units of 100ns.
        // See http://msdn.microsoft.com/en-us/library/ms683223
        // for documentation on GetProcessTimes()
        ULONGLONG getCurrentUserTime()
        {
            FILETIME ct, et, kt, ut;
            GetProcessTimes(GetCurrentProcess(), &ct, &et, &kt, &ut);
            ULARGE_INTEGER t;
            t.HighPart = ut.dwHighDateTime;
            t.LowPart = ut.dwLowDateTime;
            return t.QuadPart;
        }
    };
    

提交回复
热议问题