mohammed essam
mohammed essam

Reputation: 157

expected primary-expression before ')' token : c++

I'm new to C/C++, I've been using python, And I'm trying to get current time and partition it, But I'm having a problem acquiring the current time using ctime.

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);
}

The error is exactly:

error: expected primary-expression before ')' token

Upvotes: 0

Views: 2527

Answers (1)

Mat
Mat

Reputation: 206879

You can't pass a type to a function. You need to pass actual objects/structs. ctime takes a pointer to a time_t.

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

Also QString doesn't have a substr member function. Look at mid and related functions instead. Or use localtime/gmtime. Or better yet, use the Qt date and time objects.

Upvotes: 3

Related Questions