Jump to content

Is it just me or is it common to do this?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
davidthefat

davidthefat

    Learning Programmer

  • Members
  • PipPipPip
  • 82 posts
I just hate the string header, I dont see the point of using it... can anyone give me reasons why I should use it? I just use an array of char...

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Buffer overflows. They happen with array of char. They don't happen with string.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,715 posts
That, and you can use istringstream on them to store string representations of floats, ints, and such - and it expands to meet your needs. Otherwise you have to do a whole lot of malloc, realloc, and sprintf calls, which, as WingedPanther mentioned, can result in buffer overflows. What exactly do you hate about the string class?

#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
If you get into the standard library, you'll find that there are a LOT of powerful features in the string class that you would have to hand craft for char arrays. Besides, you can access elements of a string as if it were an array of char, so you aren't losing much. I suspect your issue with std::string is you don't feel like you're "in control" of it, somehow. The reality is that it is safer, so no need for "control" of stupid stuff.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog