简体   繁体   中英

No suitable conversion function from “const std::string” to “time_t” exists

I'm doing a conversion from epoch time to proper date and time. So far I found out that boost library could help me with this. However, I got the error No suitable conversion function from "const std::string" to "time_t" exists

    const std::string timeparser(jsonData["data"]["table"][i]["data"]["created_utc"].asString());

timeparser may consist of "1522516475"

    std::time_t btime_ = timeparser;

    std::cout << boost::posix_time::from_time_t(btime_) << endl;
    std::cout.imbue(std::locale(std::cout.getloc(), new boost::posix_time::time_facet("%H:%M:%S")));
    std::cout << boost::posix_time::from_time_t(btime_) << endl;

This doesn't work:

std::time_t btime_ = timeparser;

Because the left hand type is a number, and the right hand is a string. You need to convert:

std::time_t btime_ = std::stoi(timeparser);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM