2011-08-28 5 views
3

나는 다음과 같은 코드를 가지고 있지만이 오류 메시지입니다부스트 날짜/시간

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

컴파일 할 때 로케일 오류가 발생합니다 : 편집 후

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’ 

오류는 다음과 같습니다

In function ‘int main(int, char**)’: 
test.cpp:18:1: error: ‘locale’ was not declared in this scope 
+0

을 도움이 될 것입니다? –

+0

내가 추가하면 다음과 같습니다. 치명적인 오류 : boost/locale.hpp : 해당 파일이나 디렉토리가 없습니다. 컴파일이 종료되었습니다. – itcplpl

+0

어떤 버전의 부스트를 사용하고 있습니까? 그것은 단지 1.46+에있는 것 같습니다. http://cppcms.sourceforge.net/boost_locale/html/index.html –

답변

1

locale 앞에 누락 된 std::이 있습니다. 특히,

locale loc=locale(locale("en_US"),f); 

std::locale loc=std::locale(std::locale("en_US"),f); 

될해야합니다 그리고 당신은 #include <locale>해야합니다. getting started guide

당신은 먼저 구축해야

에서

+0

내가 그랬고 지금 오류가 있습니다 : 오류 : '로케일'이이 범위에서 선언되지 않았습니다. 변경 사항으로 내 프로그램을 편집합니다. – itcplpl

+0

@itcplpl, 죄송합니다. 나는 그 중 하나를 놓쳤습니다. 가장 안쪽의'locale'은'std ::'가 없습니다. 나는 그것을 편집했다. – rcollyer

+0

나는 그것을 고치고 고치지 만 여전히 같은 오류가 발생한다. – itcplpl

1
Boost.DateTime has a binary component that is only needed if you're using its to_string/from_string 

, this는`를 당신이/당신이`의 #include 시도 않았다해야합니까