Needing C++ Coders Help

2007-01-25 Thread Adriano Crestani
I'm begginer with C++ and I would like to know the best way to obtain a char* from a string object, for example: string name = Alice; char* namePtr = (char*) string; // this is not possible : ( Obs.: I'm needing a char* and not a const char* pointer Thanks. Adriano Crestani

Re: Needing C++ Coders Help

2007-01-25 Thread Adriano Crestani
I'm trying to use a function that requires a char* not const as a paremeter. I think strdup will help a lot, thanks ; ) Adriano Crestani On 1/25/07, Pete Robbins [EMAIL PROTECTED] wrote: On 25/01/07, Adriano Crestani [EMAIL PROTECTED] wrote: I'm begginer with C++ and I would like to know the

Re: Needing C++ Coders Help

2007-01-25 Thread Pete Robbins
OK. I have to ask what function are you calling that takes a char*? Is there an equivalent that takes const char*? Cheers, On 25/01/07, Adriano Crestani [EMAIL PROTECTED] wrote: I'm trying to use a function that requires a char* not const as a paremeter. I think strdup will help a lot,

Re: Needing C++ Coders Help

2007-01-25 Thread Luciano Resende
Thanks for helping Pete... Adriano, maybe you could describe the scenario you are trying to cover, and what's your approach (where you are trying this specific function), this could help us understand better your issue, and maybe suggest other/better approaches. On 1/25/07, Pete Robbins [EMAIL

Re: Needing C++ Coders Help

2007-01-25 Thread Pete Robbins
On 25/01/07, Adriano Crestani [EMAIL PROTECTED] wrote: I'm begginer with C++ and I would like to know the best way to obtain a char* from a string object, for example: string name = Alice; char* namePtr = (char*) string; // this is not possible : ( Obs.: I'm needing a char* and not a const

Re: Needing C++ Coders Help

2007-01-25 Thread Adriano Crestani
It's an ODBC function: SQLConnect ( SQLHDBC ConnectionHandle, /* hdbc */ SQLCHAR *ServerName, /* szDSN */ SQLSMALLINT ServerNameLength, /* cbDSN */ SQLCHAR *UserName,

Re: Needing C++ Coders Help

2007-01-25 Thread Adriano Crestani
It's an ODBC function: SQLConnect ( SQLHDBC ConnectionHandle, /* hdbc */ SQLCHAR *ServerName, /* szDSN */ SQLSMALLINT ServerNameLength, /* cbDSN */ SQLCHAR *UserName,

Re: Needing C++ Coders Help

2007-01-25 Thread Yang ZHONG
Not every API is designed extremely careful: quite some times char* doesn't mean the implementation may change the memory. I doubt SQLConnect change char*, therefore you can safely cast from const char* to char* On 1/25/07, Adriano Crestani [EMAIL PROTECTED] wrote: It's an ODBC function:

Re: Needing C++ Coders Help

2007-01-25 Thread Pete Robbins
OK ... that interface should probably have const input parameters but not much we can do about that :0( Looks like you need to copy the strings somehow.. and remember to delete the string when finished with it. Cheers, On 25/01/07, Adriano Crestani [EMAIL PROTECTED] wrote: It's an ODBC

Re: Needing C++ Coders Help

2007-01-25 Thread Pete Robbins
On 25/01/07, Yang ZHONG [EMAIL PROTECTED] wrote: Not every API is designed extremely careful: quite some times char* doesn't mean the implementation may change the memory. I doubt SQLConnect change char*, therefore you can safely cast from const char* to char* I agree. The API defines these

Re: Needing C++ Coders Help

2007-01-25 Thread Adriano Crestani
Thanks guys, you helped a lot. So I will copy the string to a char* and delete it after the usage. ; ) Adriano Crestani On 1/25/07, Pete Robbins [EMAIL PROTECTED] wrote: On 25/01/07, Yang ZHONG [EMAIL PROTECTED] wrote: Not every API is designed extremely careful: quite some times char*

Re: Needing C++ Coders Help

2007-01-25 Thread Pete Robbins
That is the belt and braces approach but if it's a perfomance issue it would be OK to follow Yang's suggestion and jsut cast it to char*. Try it and see if it works! On 25/01/07, Adriano Crestani [EMAIL PROTECTED] wrote: Thanks guys, you helped a lot. So I will copy the string to a char* and

Re: Needing C++ Coders Help

2007-01-25 Thread Adriano Crestani
OK, but when I try to do it: char* namePtr = (char*) name.c_str; I get this error message: Error36error C2440: 'type cast' : cannot convert from 'const char *(__thiscall std::basic_string_Elem,_Traits,_Ax::* )(void) const' to 'char *' I suppose that isn't allowed to cast from const to

Re: Needing C++ Coders Help

2007-01-25 Thread Yang ZHONG
char* namePtr = (char*) name.c_str(); You forgot () and that's why compiler treats c_str as function address instead of the address returned by the function. On 1/25/07, Adriano Crestani [EMAIL PROTECTED] wrote: OK, but when I try to do it: char* namePtr = (char*) name.c_str; I get this

Re: Needing C++ Coders Help

2007-01-25 Thread Jean-Sebastien Delfino
Adriano Crestani wrote: OK, but when I try to do it: char* namePtr = (char*) name.c_str; I get this error message: Error36error C2440: 'type cast' : cannot convert from 'const char *(__thiscall std::basic_string_Elem,_Traits,_Ax::* )(void) const' to 'char *' I suppose that isn't

Re: Needing C++ Coders Help

2007-01-25 Thread Adriano Crestani
The Yang solution worked, thanks a lot ; ) Adriano Crestani On 1/25/07, Jean-Sebastien Delfino [EMAIL PROTECTED] wrote: Adriano Crestani wrote: OK, but when I try to do it: char* namePtr = (char*) name.c_str; I get this error message: Error36error C2440: 'type cast' : cannot