Question

    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?

Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top