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 .
Can anyone give me an idea or example when it is
more appropriate to use a C-string over a string?
C-strings and strings
Moderator: Coders of Rage
- Netwatcher
- 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
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/
-Derek Powazek, http://powazek.com/posts/1655
blip.fm DJ profile - http://blip.fm/Noobay
current code project http://sourceforge.net/projects/vulcanengine/
- zodiac976
- 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
I am unfamiliar with "MFC". Is that bad?Netwatcher wrote:If you're using MFC...
- Netwatcher
- 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
MFC is just a wrapper for some Windows stuff. (MFC-Microsoft Foundation Class Library)zodiac976 wrote:I am unfamiliar with "MFC". Is that bad?Netwatcher wrote:If you're using MFC...
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/
-Derek Powazek, http://powazek.com/posts/1655
blip.fm DJ profile - http://blip.fm/Noobay
current code project http://sourceforge.net/projects/vulcanengine/
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: C-strings and strings
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.zodiac976 wrote:Can anyone give me an idea or example when it is
more appropriate to use a C-string over a string?
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.