I am trying to transform a string to a boost::uint64_t
the contents of pvalue
are 12345678901234567890
. the code I'm using right now is:
void setAttribute(EnumAttrTyoe pname, const void *pvalue) {
if (pname == SESS_ID) {
const char *raw_sess_id = reinterpret_cast<const char*>(pvalue);
std::string str_sess_id(raw_sess_id);
std::cout << "Trying to open session id: '" << str_sess_id << "'\n";
m_session_id = boost::lexical_cast<unsigned long long>(str_sess_id);
}
}
This one throws an exception with message "bad lexical cast: source type value could not be interpreted as target." If instead I use this code:
void setAttribute(EnumAttrTyoe pname, const void *pvalue) {
if (pname == SESS_ID) {
const char *raw_sess_id = reinterpret_cast<const char*>(pvalue);
std::string str_sess_id(raw_sess_id);
std::stringstream ss;
ss << raw_sess_id;
ss >> m_session_id;
}
}
it goes through but the value of m_session_id
is 0. I have not yet check the flags of ss
but I don't need to be a genious to know it fails. Any ideas what to do now?
UPDATE No C++11, since I cannot use it, and my compiler is VC++ 2008, boost version 1.43.0.