Board index » cppbuilder » Using Ansi String with normal string Functions

Using Ansi String with normal string Functions

I am new to Builder, and I keep running into the same problem: When I
convert a integer to a string it has become an Ansi string and when I
try to use a function like strcpy, strcmp, etc... it gives me the error:
See below: Is there some way to "cast" or convert a Ansi string or vise
versa? Thanks...Tom

[C++ Error] Unit1.cpp(21): E2034 Cannot convert 'AnsiString' to 'const
char *'
[C++ Error] Unit1.cpp(21): E2342 Type mismatch in parameter '__src'
(wanted 'const char *', got 'AnsiString')

.
.
.
void __fastcall TForm1::Edit1Change(TObject *Sender)
{
 char hhh[15] ="abc";
 strcpy(hhh,Edit1->Text);

Quote
}

//---------------------------------------------------------------------------
 

Re:Using Ansi String with normal string Functions


if  myString  is an AnsiString then use

        strcpy(destination, myString.c_str());

Also look up AnsiString in the help files, because there are a lot of
other things AnsiStrings can do...

Polomint

On Fri, 15 Sep 2000 15:48:59 -0500, tom sutherland

Quote
<tom.sutherl...@timedomain.com> wrote:
>I am new to Builder, and I keep running into the same problem: When I
>convert a integer to a string it has become an Ansi string and when I
>try to use a function like strcpy, strcmp, etc... it gives me the error:
>See below: Is there some way to "cast" or convert a Ansi string or vise
>versa? Thanks...Tom

>[C++ Error] Unit1.cpp(21): E2034 Cannot convert 'AnsiString' to 'const
>char *'
>[C++ Error] Unit1.cpp(21): E2342 Type mismatch in parameter '__src'
>(wanted 'const char *', got 'AnsiString')

>.
>.
>.
>void __fastcall TForm1::Edit1Change(TObject *Sender)
>{
> char hhh[15] ="abc";
> strcpy(hhh,Edit1->Text);
>}
>//---------------------------------------------------------------------------

Other Threads