2010-08-10 4 views

답변

36

후드 아래에서 std :: stringstream을 사용하는 boost :: lexical_cast를 사용하면 좀 더 쉽게 할 수 있습니다. 이런 경우에

#include <boost/lexical_cast.hpp> 
#include <boost/uuid/uuid_io.hpp> 

const std::string tmp = boost::lexical_cast<std::string>(theUuid); 
const char * value = tmp.c_str(); 
10

<boost/uuid/uuid_io.hpp>을 포함시킨 다음 연산자를 사용하여 uuid를 std::stringstream으로 변환 할 수 있습니다. 거기에서 필요에 따라 const char*으로 표준 변환됩니다.

자세한 내용은 the Input and Output second of the Uuid documentation을 참조하십시오.

std::stringstream ss; 
ss << theUuid; 

const std::string tmp = ss.str(); 
const char * value = tmp.c_str(); 

(당신이 "TMP"문자열이 필요한 이유에 대한 자세한 내용은, see here.)

1

당신은 부스트 ​​/ UUID/uuid_io.hpp에서 스트림 기능을 사용합니다.

boost::uuids::uuid u; 

std::stringstream ss; 
ss << u; 
ss >> u; 
26

는 다음과 같이 작동 할 수도 boost::uuids::to_string있다 : 고대 부스트 버전으로 작업하는 사람들을 위해

#include <boost/uuid/uuid.hpp> 
#include <boost/uuid/uuid_io.hpp> 

boost::uuids::uuid a = ...; 
const std::string tmp = boost::uuids::to_string(a); 
const char* value = tmp.c_str(); 
+2

:이 방법은 1.44에서 소개된다. http://www.boost.org/doc/libs/1_43_0/boost/uuid/uuid_io.hpp http://www.boost.org/doc/libs/1_44_0/boost/uuid/uuid_io.hpp – user1556435

+1

을 참조하십시오. IMHO라는 정답이어야합니다. –

관련 문제