Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

AnsiString convert in C++Builder?

Posted on 1998-12-28
5
Medium Priority
?
1,340 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 160 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

721 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