Visualizzazione dei risultati da 1 a 6 su 6
  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2006
    Messaggi
    49

    Tempo di esecuzione(funzione corretta???)

    ciao a tutti cm da titolo volevo sapere che errore c'è nella funzione che utilizzo per calcolare il tempo di esecuzione..grazie in anticipo!!!
    codice:

    void disptempo (SYSTEMTIME st, SYSTEMTIME et)
    { //Display differenza tempo tra endtime e st (start time)
    //restituisce il risultato in ore:minuti:secondi:millisecondi
    long int lt=0,lst=1,let=0,resto=0;
    int ore=0,min=0,sec=0,mls=0;
    char gs[7] [2+1]={"DO","LU","MA","ME","GI","VE",SA"};

    //calcolo start time in mls
    lst=lst+(st.wHour * 3600000); //trasforma ore in mls
    lst=lst+(st.wMinute * 60000); //trasforma min in mls
    lst=lst+(st.wSecond * 1000); //trasforma sec in mls
    lst=lst+(st.wMilliseconds); //somma mls

    //calcolo end time in mls
    let=let+(st.wHour * 3600000); //trasforma ore in mls
    let=let+(st.wMinute * 60000); //trasforma min in mls
    let=let+(st.wSecond * 1000); //trasforma sec in mls
    let=let+(st.wMilliseconds); //somma mls

    //calcolo tempo end time - start time in mls
    lt=let-lst;

    //trasforma lt da mls in ore,min,sec,mls
    resto=lt;
    ore=resto / 3600000;
    resto=resto % 3600000; //resto=resto modulo mls in 1h
    min=resto / 60000;
    resto=resto % 60000;
    sec=resto / 1000;
    resto=resto % 1000;
    mls=resto;

    cout <<gs[st.wDayOfWeek]<<" "<<st.wDay<<"/"<<st.wMonth<<"/"<<st,wYear<<" Tempo: ";
    cout <<"h"<<ore<<":m"<<min<<":s"<<sec<<":mls"<<mls<<" lt="<<lt<<"\n";

    } /* end disptempo */



    a me da errore nella 6 linea di codice (char ...) dicendo:
    error C2059: syntax error : 'string'

    e nella 36 dicendo:

    error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'struct _SYSTEMTIME' (or there is no acceptable conversion)

    error C2065: 'wYear' : undeclared identifier

    error C2297: '<<' : illegal, right operand has type 'char [11]'

  2. #2
    scusami che linguaggio è? VVoVe: VVoVe: VVoVe:


    EDIT:Scusa pensavo di essere in php

  3. #3
    Utente di HTML.it
    Registrato dal
    Apr 2006
    Messaggi
    49
    ovviamente c++\

  4. #4
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284
    Fare la differenza tra 2 SYSTEMTIME è una pessima idea, oltre che scomodo. L'ideale è convertire SYSTEMTIME in FILETIME (funzione SystemTimeToFileTime) e poi mettere il valore di FILETIME in un ULARGE_INTEGER e quindi fare delle normali operazioni matematiche a 64 bit.

    Se devi prendere il tempo di sistema in 2 istanti diversi puoi anche evitare di usare SYSTEMTIME e prendere direttamente il tempo in FILETIME (funzione GetSystemTimeAsFileTime).
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

  5. #5
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,465

    Moderazione

    Originariamente inviato da robylo
    ovviamente c++\
    Va indicato anche nel titolo. Ho corretto io.

    Ciao!
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

  6. #6
    Si possono anche usare le funzioni standard del C (header ctime), così da rimanere nell'ambito di C compatibile.
    Amaro C++, il gusto pieno dell'undefined behavior.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.