954,224 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

AnsiString to Const Char*

I have an Edit Box on a form. The text entered in it is stored as an AnsiString. I must pass the input AnsiString data to a function that requires a const char* as a parameter. How can I pass the AnsiString as a const char*? I would appreciate any help on this.

Helter

Helter
Newbie Poster
2 posts since Jul 2004
Reputation Points: 10
Solved Threads: 0
 

I've got

AnsiString foo;

How do I pass this to a function which needs a char?
(eg., strcpy, etc).

Answer:

foo->c_str().

The c_str() method of the AnsiString class returns
a const char* which can be used to read, but not
modify, the underlying string.

meabed
Junior Poster
Team Colleague
139 posts since May 2004
Reputation Points: 55
Solved Threads: 3
 

I've got

AnsiString foo;

How do I pass this to a function which needs a char? (eg., strcpy, etc).

Answer:

foo->c_str().

The c_str() method of the AnsiString class returns a const char* which can be used to read, but not modify, the underlying string.

Thank you. It worked fine.

Helter
Newbie Poster
2 posts since Jul 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You