Re: Understanding char*
Big Brian wrote:
[color=blue][color=green][color=darkred]
>>>Could someone explain for me what is happening here?[/color]
>>
>>char* is not a string type. It is a pointer to a single character.
>>At this point in your career you should stay clear ofit. Use the std::string type instead.[/color]
>
>
> Everybody needs to understand c style strings as well.[/color]
Yes, but they should avoid them. Beginners and experts alike should
prefer std::string.
[color=blue]
> I've worked on
> projects where you couldn't use std::string.[/color]
So, projects where you weren't allowed to use C++? (At least not all of
it.) I wonder why that restriction would be placed on a project written
in C++.
[color=blue]
> And you never know when
> you're going to have to maintain old code which uses them.[/color]
Yeah. When maintaining that kind of code, I recommend converting it to
use std::string.
The advantages of std::string over C-style strings are clear. Of course
a good programmer should now how to use messy things like C-style
strings, but he should also know better than to use them (at least most
of the time).
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Big Brian wrote:
[color=blue][color=green][color=darkred]
>>>Could someone explain for me what is happening here?[/color]
>>
>>char* is not a string type. It is a pointer to a single character.
>>At this point in your career you should stay clear ofit. Use the std::string type instead.[/color]
>
>
> Everybody needs to understand c style strings as well.[/color]
Yes, but they should avoid them. Beginners and experts alike should
prefer std::string.
[color=blue]
> I've worked on
> projects where you couldn't use std::string.[/color]
So, projects where you weren't allowed to use C++? (At least not all of
it.) I wonder why that restriction would be placed on a project written
in C++.
[color=blue]
> And you never know when
> you're going to have to maintain old code which uses them.[/color]
Yeah. When maintaining that kind of code, I recommend converting it to
use std::string.
The advantages of std::string over C-style strings are clear. Of course
a good programmer should now how to use messy things like C-style
strings, but he should also know better than to use them (at least most
of the time).
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Comment