Hi, to all, I'm having the following problem:
I'm trying to convert a CString to long(or number), but the number that is in the Cstring is too big and I loose data of the number.
I was thinking in using instead of long use the variable ULONGLONG, but the problem is that I don't know if there is Build-in method that converts Cstring to ULONGLONG.
Any ideas, how I can solve this problem, convert a big number stored in a CString and save it in a variable number.
I try this but is not working

CString pi_sString = ''1099511627775";
long nNumber = atol(pi_sString);

Thanks :rolleyes:

I think you can use sprintf()

__int64 big_number;

sprintf((LPCTSTR)pi_sString, "%i64d", &big_number);

long integers also have a maximum value. They are made up of 4 bytes (32bits) (depending on each pc) and can only hold upto a certain number. If you try to go past this number you will wrap around and start at the beginning. Try using unsigned long int, which will double the maximum value the long integer can handle

long integers also have a maximum value.

True, it's 4294967296 to be exact. So that won't work for you, I suggest you go with Ancient Dragon's solution and use 64 bits.

Regard Niek

Thanks for the quick reponses,
I found a solution, store the value in a ULONGLONG variable and use the "_atoi64" method

ULONGLONG nBigNumber = _atoi64(pi_sString);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.