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?
 
Infinity08Connect With a Mentor Commented:
>>  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
 
George TokasConnect With a Mentor Commented:
>>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
All Courses

From novice to tech pro — start learning today.