|
AnsiString c_str() example In C++Builder Help
AnsiString::c_str() returns a non const temporary pointer to the internal string buffer in the AnsiString object.
The pointer is invalid once the statement in which it is used has finished executing.
That is,don't do something like this:
char* cp = Edit1->Text.c_str();
char* cp2 = strtok( cp, " \t\n" ); // cp may no longer be valid
If you need a persistent pointer, you MUST copy the string into its own buffer:
char* cp = new char[ Edit1->Text.Length() + 1 ];
strcpy( cp, Edit1->Text.c_str() );
Aries 님이 쓰신 글 :
: Hi,
:
: I'm using Borland C++Builder 4 facility (i.e InputBox) for getting inputs. The InputBox returns an 'AnsiString' type. But I want to parse this input (AnsiString type) into my variable (Char type), e.g. Char c[50].
: Obviously I can not do this :
: c[50]=InputBox->Text;
: So.. Does anybody know how to convert an 'AnsiString' type into a 'Char' type in Borland C++Builder ?
: Please explain to me using some simple examples/codes.
:
: Regards,
: Aries
:
: Nb. Answer in English please.
:
|