Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a string to a unsigned long long in c++

Convert a string to a unsigned long long.

string str = "0x1232"

How do I convert to a unsigned long long.

This is what i've tried.

unsigned long long ull;
ull = stoull(str, NULL, 0);

Error:

 error: identifier "stoull" is undefined
                        ull = stoull(str, NULL, 0);

Can you give me some pointers?

like image 383
pistal Avatar asked Jan 02 '26 09:01

pistal


1 Answers

First of all it's strtoull (notice the r). Second of all, it's an old C-style function and can't handle std::string directly. You either have to pass it str.c_str() or use the new std::stoull.

like image 69
Some programmer dude Avatar answered Jan 03 '26 23:01

Some programmer dude



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!