Solved

AnsiString convert in C++Builder?

Posted on 1998-12-28
5
1,307 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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.
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.

756 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