Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text.c_str versus standard string

Status
Not open for further replies.

okaypi

Programmer
Feb 15, 2011
1
Hi
i am using borland C++ 6, my question regarding the following code
void __fastcall TForm1::Button1Click(TObject *Sender)
{

char* S = Edit1->Text.c_str();
Edit2->Text = strlen(S); //gives erroneous result

AnsiString st = Edit1->Text;
Edit3->Text = st.Length(); //gives correct results
}

if the text in Edit1 is more than 3 Chars then the length of the string written to
Edit2 and Edit3 will be correct.
but if the Text in Edit1 <= 3 then number 1 will be written in Edit2 and the coorect
number in Edit3
why is this behaviour regarding the results in Edit2 when the string lenght <= 3 characters ? thanks

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top