H
hamishd
Is this possible? Sorry if this question isn't relevant here.
actually, I'm really trying to convert a unsigned char * to an int
actually, I'm really trying to convert a unsigned char * to an int
hamishd said:Is this possible? Sorry if this question isn't relevant here.
actually, I'm really trying to convert a unsigned char * to an int
Are you trying to convert the value of the pointer, or where the pointer is
pointing to?
Either way, reinterpret_cast is what you want.
reinterpret_cast<int>( Foo );
I think reinpterpret_cast does *NOT* work with constnessJim said:Are you trying to convert the value of the pointer, or where the pointer is
pointing to?
Either way, reinterpret_cast is what you want.
reinterpret_cast<int>( Foo );
Barry said:I think reinpterpret_cast does *NOT* work with constness
maybe static_cast and const_cast together will work
Erik said:reinterpret_cast should not be needed it it's a unsigned char -> int
conversion the OP is trying to do, both are integer types so a normal
assignment should do, right?
There isn't a portable way to do this, on many systems a char* is biggerhamishd said:Is this possible? Sorry if this question isn't relevant here.
actually, I'm really trying to convert a unsigned char * to an int
Are you trying to convert the value of the pointer, or where the pointer is
pointing to?
Either way, reinterpret_cast is what you want.
reinterpret_cast<int>( Foo );
What does RegQueryValueEx do to the ikey parameter?hamishd said:Are you trying to convert the value of the pointer, or where the pointer is
pointing to?
Either way, reinterpret_cast is what you want.
reinterpret_cast<int>( Foo );
Below is exactly what I'm doing. I want to read a value from the
registry. Let's say the registry value is "453".
unsigned char ikey[256];
ULONG ilen = 256;
HKEY ihKey;
RegQueryValueEx(ihKey, "Value", 0, NULL, ikey, &ilen);
But now ikey is not an int, i want an int of value 453.
int RegistryVal = reinterpret_cast<int>(ikey);
This does not work.
Why not just use static_cast<char*>(ikey)?The reason i asked about converting to a constr char * is that I
wanted to use atoi()
Ian Collins said:There isn't a portable way to do this, on many systems a char* is bigger
than an int.
hamishd said:Are you trying to convert the value of the pointer, or where the pointer
is
pointing to?
Either way, reinterpret_cast is what you want.
reinterpret_cast<int>( Foo );
Below is exactly what I'm doing. I want to read a value from the
registry. Let's say the registry value is "453".
unsigned char ikey[256];
ULONG ilen = 256;
HKEY ihKey;
RegQueryValueEx(ihKey, "Value", 0, NULL, ikey, &ilen);
But now ikey is not an int, i want an int of value 453.
int RegistryVal = reinterpret_cast<int>(ikey);
This does not work.
The reason i asked about converting to a constr char * is that I
wanted to use atoi()
hamishd said:Are you trying to convert the value of the pointer, or where the pointer is
pointing to?
Either way, reinterpret_cast is what you want.
reinterpret_cast<int>( Foo );
Below is exactly what I'm doing. I want to read a value from the
registry. Let's say the registry value is "453".
unsigned char ikey[256];
ULONG ilen = 256;
HKEY ihKey;
RegQueryValueEx(ihKey, "Value", 0, NULL, ikey, &ilen);
But now ikey is not an int, i want an int of value 453.
int RegistryVal = reinterpret_cast<int>(ikey);
This does not work.
The reason i asked about converting to a constr char * is that I
wanted to use atoi()
Jim Langston said:hamishd said:Below is exactly what I'm doing. I want to read a value from the
registry. Let's say the registry value is "453".
unsigned char ikey[256];
ULONG ilen = 256;
HKEY ihKey;
RegQueryValueEx(ihKey, "Value", 0, NULL, ikey, &ilen);
But now ikey is not an int, i want an int of value 453.
int RegistryVal = reinterpret_cast<int>(ikey);
This does not work.
The reason i asked about converting to a constr char * is that I
wanted to use atoi()
Oh. You want to convert "453" to an int. I would use stringstream, which
is an alternative to atoi
std::stringstream convert;
convert << ikey;
int Value;
convert >> value;
Nope said:int Value;
convert >> Value;
may also work. Not sure if stringstream has a constructor taking a char*
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.