Solved

AnsiString convert in C++Builder?

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

776 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