"hamishd" <Hamish.Dean@gm ail.comwrote in message
news:1186219573 .640775.272620@ x35g2000prf.goo glegroups.com.. .
>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_cas t is what you want.
reinterpret_cas t<int>( Foo );
reinterpret_cas t 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?
"hamishd" <Hamish.Dean@gm ail.comwrote in message
news:1186219573 .640775.272620@ x35g2000prf.goo glegroups.com.. .
>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_cas t is what you want.
reinterpret_cas t<int>( Foo );
>
>
I think reinpterpret_ca st does *NOT* work with constness
maybe static_cast and const_cast together will work
reinterpret_cas t 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?
>
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_cas t is what you want.
reinterpret_cas t<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".
>>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_cas t is what you want.
>reinterpret_ca st<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.
>
What does RegQueryValueEx do to the ikey parameter?
int RegistryVal = reinterpret_cas t<int>(ikey);
>
This does not work.
Why should it?
The reason i asked about converting to a constr char * is that I
wanted to use atoi()
>
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_cas t is what you want.
>reinterpret_ca st<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_cas t<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::stringstre am convert;
convert << ikey;
int Value;
convert >value;
std::string convert( ikey );
int Value;
convert >Value;
may also work. Not sure if stringstream has a constructor taking a char*
hamishd <Hamish.Dean@gm ail.comwrote in message...
On Aug 4, 6:47 pm, "Jim Langston" <tazmas...@rock etmail.comwrote :
"hamishd" <Hamish.D...@gm ail.comwrote in message
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_cas t is what you want.
reinterpret_cas t<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_cas t<int>(ikey);
This does not work.
The reason i asked about converting to a constr char * is that I
wanted to use atoi()
Why?
#include <iostream>
#include <sstream>
{ // main() or ?
unsigned char ikey[256] = "453\0";
std::stringstre am sis;
sis << ikey;
int number;
sis >number;
std::cout<<"num ber = "<<number<<std: :endl;
}
// out: number = 453
Jim Langston <tazmaster@rock etmail.comwrote in message...
"hamishd" <Hamish.Dean@gm ail.comwrote in message...
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_cas t<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::stringstre am convert;
convert << ikey;
int Value;
convert >value;
>
// std::string convert( ikey );
std::string Sconvert( ikey );
std::stringstre am convert( Sconvert );
Nope, I tried it. (and the casts got real ugly! <G>).
int Value;
convert >Value;
>
may also work. Not sure if stringstream has a constructor taking a char*
It does for 'char*', but not for 'unsigned char*' (not on my old MinGW).
// -------
char const scc[] = "453\0";
std::istringstr eam is( scc ); // no problem
// -------
unsigned char const scc[] = "453\0";
std::istringstr eam is( scc );
// error: invalid conversion from `const unsigned char*' to `
// const char*'
// error: initializing argument 1 of std::basic_stri ng...
(again, the casts got real ugly! <G>).
// -------
Comment