Reputation: 1109
I'm using VS 2008 to create a C++ DLL (not managed) project and I need convert a char* to a long long type. Is there an easy way to do it?
Thanks in advance :)
Upvotes: 9
Views: 34905
Reputation: 163
Another option is using stoll() found within the string library. Takes a C++ string.
long long ll = std::stoll(mystr);
Upvotes: 7
Reputation: 46813
The easiest way is to use the std::stringstream (it's also the most typesafe...)
std::stringstream sstr(mystr);
__int64 val;
sstr >> val;
You may need to target a 64-bit application for this to work.
Upvotes: 15
Reputation: 14121
If you're using boost, lexical_cast is the way to go, in my opinion.
long long ll = boost::lexical_cast<long long>(mystr)
Upvotes: 8