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
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*"
> > 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 as Input parameters so it SHOULD be safe
to
> just cast the const char* to SQLCHAR*
>
> but...
>
> On 1/25/07, Adriano Crestani <[EMAIL PROTECTED]> wrote:
> > >
> > > It's an ODBC function:
> > >
> > > SQLConnect       (
> > >               SQLHDBC           ConnectionHandle,       /* hdbc */
> > >               SQLCHAR           *ServerName,             /* szDSN */
> > >               SQLSMALLINT       ServerNameLength,       /* cbDSN */
> > >               SQLCHAR           *UserName,               /* szUID */
> > >               SQLSMALLINT       UserNameLength,         /* cbUID */
> > >               SQLCHAR           *Authentication,         /*
szAuthStr
> */
> > >               SQLSMALLINT       AuthenticationLength);
> > >
> > >
> > > I'm needing to turn the server name that is a string object
> > > into a char* to cast it to SQLCHAR* and I didn't find any other
> > > function that takes const SQLCHAR* instead of SQLCHAR*. Thanks again
;
> )
> > >
> > >
> > > .
> > >
> > >
> > > On 1/25/07, Pete Robbins <[EMAIL PROTECTED]> wrote:
> > > >
> > > > 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, 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 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
> > > > > > >
> > > > > > >
> > > > > >
> > > > > > std::string has a .c_str() method to return the const char*
> > > > > > const char* namePtr = name.c_str();
> > > > > >
> > > > > > Why do you need char* and not const char*? You could cast the
> > value
> > > to
> > > > > > char* but it is const for a good reason... you should not use
c
> > > > > > functions to manipulate the characters in std:string!
> > > > > >
> > > > > > You can take a copy of the string using strdup.
> > > > > >
> > > > > > Cheers,
> > > > > >
> > > > > > --
> > > > > > Pete
> > > > > >
> > > > > >
> > >
---------------------------------------------------------------------
> > > > > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > > > > For additional commands, e-mail:
[EMAIL PROTECTED]
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > > Pete
> > > >
> > > >
> > >
> > >
> >
> >
> > --
> >
> > Yang ZHONG
> >
> >
>
>
> --
> Pete
>
>




--
Pete

Reply via email to