char causes segfaults more than strings?

This is a discussion on char causes segfaults more than strings? within the C++ Programming forums, part of the General Programming Boards category; Hello all, I am very new to c++, (but have been a developer for 15 years) and have a question. ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    6

    char causes segfaults more than strings?

    Hello all,

    I am very new to c++, (but have been a developer for 15 years) and have a question.

    I work with other c++ programmers. One loves chars the other says they could cause seg faults and I should use strings.

    What are your thoughts?

    Thanks,
    Michael

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by TheBigOnion View Post
    Hello all,

    I am very new to c++, (but have been a developer for 15 years) and have a question.

    I work with other c++ programmers. One loves chars the other says they could cause seg faults and I should use strings.

    What are your thoughts?

    Thanks,
    Michael
    If you know how to use character arrays, they're perfectly safe. If you don't, then not only can your application segfault but you can add serious security flaws to your application.
    But in my opinion, you have to learn about char arrays.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,264
    Perhaps you are talking about using pointers to char to work with null terminated strings. If so, it is true that working with them can be more error prone than working with string objects.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    std::string does things with you (manage memory, ensure that enough memory is allocated etc). With C style strings you'd have to take care of these things yourself. You'd write more code and have more chances to screw things up.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char compile error
    By dallypost in forum C Programming
    Replies: 10
    Last Post: 03-18-2010, 04:54 PM
  2. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  3. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 12:36 PM
  4. How do i un-SHA1 hash something..
    By willc0de4food in forum C Programming
    Replies: 4
    Last Post: 09-14-2005, 06:59 AM
  5. Passing structures... I can't get it right.
    By j0hnb in forum C Programming
    Replies: 6
    Last Post: 01-26-2003, 11:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21