Page 1 of 1

C-strings and strings

Posted: Wed Jul 08, 2009 11:18 am
by zodiac976
I tend to use strings all the time and rarely use C-
strings, just like references and pointers I used
references a ton more than pointers but now I am
using pointers and references about the same now
maybe more with pointers :lol:.

Can anyone give me an idea or example when it is
more appropriate to use a C-string over a string?

Re: C-strings and strings

Posted: Wed Jul 08, 2009 11:23 am
by Netwatcher
If you're using MFC...

Re: C-strings and strings

Posted: Wed Jul 08, 2009 11:40 am
by zodiac976
Netwatcher wrote:If you're using MFC...
I am unfamiliar with "MFC". Is that bad? :(

Re: C-strings and strings

Posted: Wed Jul 08, 2009 11:54 am
by Netwatcher
zodiac976 wrote:
Netwatcher wrote:If you're using MFC...
I am unfamiliar with "MFC". Is that bad? :(
MFC is just a wrapper for some Windows stuff. (MFC-Microsoft Foundation Class Library)

MFC's Cstring has a better performance, better interface, and no explicit casting (Cstring's LPCTSTR() vs std::string's c_str()) that's as far as I know (it has some other neat features string doesn't have)

Re: C-strings and strings

Posted: Fri Jul 17, 2009 7:11 pm
by MarauderIIC
zodiac976 wrote:Can anyone give me an idea or example when it is
more appropriate to use a C-string over a string?
I think the general rule would be that if you can use C++ strings, use them. Hardware would be the limiting factor. If you're programming for a console or handheld or phone or something, you're probably going to be using C-strings, so that you have total control over how long the strings can be, and hence, how much memory they take.

Also, some handy functions like sprintf (which you can use for int to string conversion) require C-strings, so you might use a C-string for a second and then convert it back to a C++-string.