开发者

How to convert DWORDLONG to a char *?

开发者 https://www.devze.com 2023-04-06 23:08 出处:网络
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 th
    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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号