2012-05-13 55 views
0

我是新來的C/C++,我一直在使用python,而我試圖獲取當前時間並對其進行分區,但是我遇到了問題使用ctime獲取當前時間。''''之前預期的初級表達式令牌:C++

float t2lmst(){ 
    QString t = ctime(time_t); //line with error 
    QString year =t.substr(20,4); 
    QString monthn =t.substr(4,3); 
    QString day =t.substr(8,2); 
    QString hour =t.substr(11,2); 
    QString minute =t.substr(14,2); 
    QString second =t.substr(17,2); 
} 

錯誤正是:

error: expected primary-expression before ')' token 

回答

3

您可以將未類型傳遞給函數。你需要傳遞實際的對象/結構。 ctime需要一個指向time_t的指針。

time_t now = time(0); 
QString t = ctime(&now); 

此外QString不具有substr成員函數。請看mid和相關功能。或使用localtime/gmtime。或者更好的是,使用Qt日期和時間對象。

相關問題