How to convert DWORDLONG to a char *?
res = pRecord->Usn ;
char sres[1024];
strcpy(sres,"");
ltoa(res,sres, 10);
I have this variable res, which开发者_运维百科 is of type DWORDLONG
, and I am trying to convert it into a string so that I can insert it into the database.
Also, how would I convert it back. Is there a equivalent of ltoa, or do you have to write the logic yourself?
Use
boost::lexical_cast<std::string>(res);
or
std::ostringstream o;
o << res;
o.str();
or in C++11
std::to_string(res);
For going back in C++11 you would use
res=std::stoull(str)
or in C *shiver *
char* end;
res=strtoull(str.c_str(),&end,10);
精彩评论