leave C++ strings. get on the char* boat.

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

User avatar
Arce
Jealous Self-Righteous Prick
Jealous Self-Righteous Prick
Posts: 2153
Joined: Mon Jul 10, 2006 9:29 pm

Re: leave C++ strings. get on the char* boat.

Post by Arce »

Just host via FileZilla? ;P

I do that sometimes when i need to access home shit from different location. Compliments, marauder. ;P
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
User avatar
BOMBERMAN
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 39
Joined: Wed Jan 14, 2009 5:00 pm

Re: leave C++ strings. get on the char* boat.

Post by BOMBERMAN »

Thanks avansc. Really useful topic :)
My english sucks!
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: leave C++ strings. get on the char* boat.

Post by Ginto8 »

I see what you're saying avansc, but there's really not too much difference between char*'s and strings. And strings are almost MORE flexible.

1) both of them are arrays:

Code: Select all

char *c_string = "Hi\n"
string cplusplus_string = "Hi\n"

cout << c_string << cplusplus_string;
cout << c_string[0] << cplusplus_string[0]
I may be wrong, but this should output:
Hi
Hi
HH
2) strings let you decide whether you want to pass a char* or a string to a function, if you're passing it to a function. It can also "become" a const char* for things like opening files by using c_str(), but with char*'s I guess you could const_cast it?

3) strings have quite a few functions to make it easier to do certain things with a string (see here.

If I'm incorrect at any point, please correct me; I can't say that I'm an expert with either strings or char*'s, I was just putting in my two cents.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Post Reply