C-strings and strings

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
zodiac976
Chaos Rift Regular
Chaos Rift Regular
Posts: 156
Joined: Thu Jun 18, 2009 10:03 am
Current Project: Booklet & Text RPG
Favorite Gaming Platforms: PC, PS3, PSP
Programming Language of Choice: C++
Location: AL
Contact:

C-strings and strings

Post 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?
User avatar
Netwatcher
Chaos Rift Junior
Chaos Rift Junior
Posts: 378
Joined: Sun Jun 07, 2009 2:49 am
Current Project: The Awesome Game (Actual title)
Favorite Gaming Platforms: Cabbage, Ground beef
Programming Language of Choice: C++
Location: Rehovot, Israel

Re: C-strings and strings

Post by Netwatcher »

If you're using MFC...
"Programmers are the Gods of their tiny worlds. They create something out of nothing. In their command-line universe, they say when it’s sunny and when it rains. And the tiny universe complies."
-Derek Powazek, http://powazek.com/posts/1655

blip.fm DJ profile - http://blip.fm/Noobay
current code project http://sourceforge.net/projects/vulcanengine/
User avatar
zodiac976
Chaos Rift Regular
Chaos Rift Regular
Posts: 156
Joined: Thu Jun 18, 2009 10:03 am
Current Project: Booklet & Text RPG
Favorite Gaming Platforms: PC, PS3, PSP
Programming Language of Choice: C++
Location: AL
Contact:

Re: C-strings and strings

Post by zodiac976 »

Netwatcher wrote:If you're using MFC...
I am unfamiliar with "MFC". Is that bad? :(
User avatar
Netwatcher
Chaos Rift Junior
Chaos Rift Junior
Posts: 378
Joined: Sun Jun 07, 2009 2:49 am
Current Project: The Awesome Game (Actual title)
Favorite Gaming Platforms: Cabbage, Ground beef
Programming Language of Choice: C++
Location: Rehovot, Israel

Re: C-strings and strings

Post 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)
"Programmers are the Gods of their tiny worlds. They create something out of nothing. In their command-line universe, they say when it’s sunny and when it rains. And the tiny universe complies."
-Derek Powazek, http://powazek.com/posts/1655

blip.fm DJ profile - http://blip.fm/Noobay
current code project http://sourceforge.net/projects/vulcanengine/
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: C-strings and strings

Post 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.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Post Reply