Solved

AnsiString convert in C++Builder?

Posted on 1998-12-28
5
1,324 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

623 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