Reputation:
Here's what i want to do.
ptime now = second_clock::local_time();
date today = now.date();
today.day_of_week();
string day = "Sat";
if(day == to_string(today.day_of_week()))
{
//perform an action
}
else
{
//perform another action
}
The code compiles but the program never executes the if block. How else can i convert day_of_week() to string?
Upvotes: 3
Views: 2942
Reputation: 392911
I suggest boost::lexical_cast<>
here:
std::string day = boost::lexical_cast<std::string>(today.day_of_week());
Or simply:
std::cout << today.day_of_week();
#include <boost/date_time/posix_time/posix_time_io.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/lexical_cast.hpp>
int main() {
auto now = boost::posix_time::second_clock::local_time();
auto today = now.date();
std::string day = boost::lexical_cast<std::string>(today.day_of_week());
std::cout << today.day_of_week();
}
Prints
Fri
Upvotes: 5