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 :)
We can convert String to long in java using Long. parseLong() method.
There are many methods for converting a String to a Long data type in Java which are as follows: Using the parseLong() method of the Long class. Using valueOf() method of long class. Using constructor of Long class.
The strtoll() function in C++ interprets the contents of a string as an integral number of the specified base and return its value as a long long int. This function also sets a pointer to point to the first character after the last valid character of the string if there is any, otherwise the pointer is set to null.
By converting a string into long we are translating the value of string type to long type. In Python3 int is upgraded to long by default which means that all the integers are long in Python3. So we can use int() to convert a string to long in Python.
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.
C++ FAQ
If you're using boost, lexical_cast is the way to go, in my opinion.
long long ll = boost::lexical_cast<long long>(mystr)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With