I have the following code but get the locale error when I try to compile
#include <iostream>
#include <string>
#include <locale>
#include "boost/date_time/gregorian/gregorian.hpp"
#include <boost/date_time/gregorian/parsers.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/posix_time/posix_time_io.hpp>
using namespace boost::posix_time;
using namespace boost::gregorian;
int main(int argc, char *argv[])
{
std::string ds("2011-01-02");
date dt(from_string(ds));
date_facet *f=new date_facet("%Y-%m-%d");
std::locale loc=std::locale(std::locale("en_US"),f);
std::cout.imbue(loc);
time_facet *facet = new time_facet("%Y-%m-%d %H:%M:%S");
std::cout<<second_clock::local_time()<<std::endl;
return 0;
}
This is the error message:
In function ‘int main(int, char**)’:
test.cpp:18:1: error: ‘locale’ was not declared in this scope
test.cpp:18:8: error: expected ‘;’ before ‘loc’
after the edits, the error is:
In function ‘int main(int, char**)’:
test.cpp:18:开发者_开发技巧1: error: ‘locale’ was not declared in this scope
Your missing std::
in front of locale
. Specifically,
locale loc=locale(locale("en_US"),f);
should become
std::locale loc=std::locale(std::locale("en_US"),f);
And you need to #include <locale>
.
Boost.DateTime has a binary component that is only needed if you're using its to_string/from_string
from the getting started guide
You should build it first, this should help
精彩评论