How to convert string time to unsigned int in c++

I need to convert string time to unsigned int i test my program with atoi/strtoul/atol and string stream but they don’t work correctly what am i missing???

 string CurrentTime(){
        time_t rawtime;
        struct tm * timeinfo;
        char bffr [80];

        time (&rawtime);
        timeinfo = localtime (&rawtime);

        strftime (bffr,80,"%T",timeinfo);
        // puts (bffr);

        return bffr;
    }

    int main(){
    string new_time;
    new_time = CurrentTime();
    stringstream strValue;
        strValue << new_time;
    unsigned int stime;
        strValue >> stime;
    cout<<stime<<endl;
    cout<<new_time<<endl;
    }

and

 int main(){
        string new_time;
        new_time = CurrentTime();
unsigned int stime =atoi(new_time.c_str());
cout<<stime<<endl;
cout<<new_time<<endl;

but both of them print stime :just only hour for example 10

and print new_time: for example 10:20:15


Source: c++

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.