Which string class would you use?

I'm just starting the process of moving a very large C++ Builder/VCL application from C++ Builder 6 to Rad Studio 2010.

Most of the application uses Strings.  Many calls are made to external libraries that require char *'s, so there's liberal use of mystr.c_str() calls.  This is, of course, now causing a tremendous amount of work to bring up to date.  Note that DO NOT need Unicode support.  This little 3-person company will not be going international.  Ever.

So my question is, if you were going to essentially re-write string usage in your application, what would you use? So far I've found::

1. use String, and convert when needed (which is pretty much everywhere)
2. only use String when dealing with UI code, and std::string everywhere else.

I'm tempted to create my own string class so that c_str() would return the old char * pointers, a_str() to return ansi strings, and w_str() to return the new wide string that the VCL functions need (probably derived from std::string).  A little voice in the back of my head is voting no on that one.

Soooo.... what's your recommendation?
kmustang1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Infinity08Commented:
>>  Many calls are made to external libraries that require char *'s,

Do you mean const char* or char* ?

If const char*, just stick with std::string.
If char* (and those functions could modify the string), you cannot use std::string directly, but you can pass in an array of char, and convert back to std::string after the call.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
George TokasCommented:
>>Most of the application uses Strings.  Many calls are made to external libraries that require char *'s
Maybe it will be better to make functions dealing with those external libraries and convert from AnsiString to char*...
I mean INSTEAD of calling directly the external libraries use a wrapper instead...
The same problem I have too dealing with Direct3D in TCDX9 wrapper set of classes...
What I am doing is that proposed...

George Tokas.
0
kmustang1Author Commented:
The code I'm updating is already written, so I haven't really dove in to it yet... (dived?  whatever :)  I've done a little test poking around, but have really only scratched the surface.  Thought I'd get all engineer-like and come up with a plan before I went in and started shredding.

Most of char*'s are const.  Where data is returned, it uses old-fashioned C array-of-char buffers.

I like the wrapper idea, but am not sure if it's worth the effort at this point. It probably is, but there are at least not-insignificant external libraries that I would have to wrap up.  I'll probably start doing that and see if I can get through it in a reasonable amount of time.

Thanks for the recommendation Infinity08!
0
George TokasCommented:
I understand but try to understand the following:
DirectX (3D, sound, whatever) using char* to access dll's...
I know that it is NOT an easy task but I allready used the way I'm proposing and I get good(?) results...

George Tokas.
0
kmustang1Author Commented:
I was hoping for some more insight to the use of AnsiString vs. std::string.  Both posters did help, though, and are worthy of points.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.