Solved

AnsiString convert in C++Builder?

Posted on 1998-12-28
5
1,288 Views
Last Modified: 2010-08-05
I use C++Builder and get value from Text property of a TEdit  object, it's type is ansi string but I can not work with ansi string (I want convert it to integer number when user enter a number to that Tedit object).

Like this:
int got;
char *s;
s = A->Text;//A is a TEdit object
got = atoi(s);

And Builder report an syntax error : "Can not convert System::AnsiString to char *..." in line s = A->Text;

Please help me to convert value from A->Text to number in variable got.
Thank you and Happy New Year!
0
Comment
Question by:nhhoang
  • 3
5 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1181140
how about this....

int got = StrToInt(EditBox->Text);

ShowMessage(IntToStr(got));

Hope this helps...

-Viktor
--Ivanov
0
 

Author Comment

by:nhhoang
ID: 1181141
I have known the answer not like what you said (C++Builder do not have StrtoInt)
function convert ansi string to string (I found it in FAQ in Borland site) c_str()

0
 
LVL 10

Accepted Solution

by:
viktornet earned 80 total points
ID: 1181142
If you really are using C++ Buildeer which is for windows that's the way to convert strings to integers and integers to strings... I've tried that many times and it works.. Just try it and you'll see that it works....

int got = StrToInt(Edit1->Text);

ShowMessage(IntToStr(got));

This one works.... I tested it... That's if you are using Borland's C++ Builder....

This functions work because C++ Builder's libraries are created with Pascal, and the same functions work....

I hope you accept my answer now, because it's correct. YOu asked a question and answered it, so I think I deserve the credit...

-Viktor
--Ivanov
0
 
LVL 1

Expert Comment

by:MCoroli
ID: 1181143

That is from C++Builder help.
Seems i used it
Regards

AnsiString::ToInt

Description

Converts a string to an integer, throwing an exception if the string is invalid.

int __fastcall ToInt() const;

Converts the given string to an integer value and returns the integer. If the string doesn't contain a valid value, an EConvertError exception is thrown.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1181144
StrToInt() does the same thing....
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now