I have a question in conversion of String into value.
Following is the sample code I tried.
I am trying this on C++ Builder XE4.
String strSize = L"64420392960"; // 64GB
size_t size;
size = strSize.ToDouble(); // returns 4290850816
char *end_ptr;
size = strtol(AnsiString(strSize).c_str(), &end_ptr, 10); // returns 0
Both of ToDouble() and strtol() didn't work.
I understand that strtol didn't work because long type is up to 4.3GB.
Are there any function in C++ Builder XE4, with which I can convert the strSize into size_t value when I treat 64GB or several hundreds of GB (e.g. 500GB)?
You don't have a 64GB string, which would be a string that's 64 gigabytes in size. You have a string containing a decimal number representing a value of about 64 gig.
The standard function you're looking for is strtoll
, which returns a long long
result. It's been a standard C function since the 1999 standard, and if I'm not mistaken was added to the C++ standard as of 2011.
(The question is whether C++ Builder XE4 supports strtoll
.)
If size_t
on your system is only 32 bits, there's no way to get a size_t
value that big. If it's 64 bits, strtoll
should do the trick.