Being in the development of a project. our group is confused about what shall be the better one c++ string or simple c string allocation. Thanks in advance.
Being in the development of a project. our group is confused about what shall be the better one c++ string or simple c string allocation. Thanks in advance.
john
I would go for c++ string as it provide many useful functions compared to c string
c++ string dosent puts much overhead .(Other members can comment on this)
It better to use C++ strings as it avoids many common C pointer mistakes
I agree with Raghuram on this. The likely hood of string introducing much (if any) overhead above you allocating you own memory for C strings is low and use of string greatly enhances project maintainablity and reduces the risk of bugs associated with pointers and memory allocation.
All I know is that std::strings are very easy to work with compared with messy character arrays/pointers in C. I'd trust Banfa and Prag. about the overhead issues (or, in this case, the lack of overhead), so it looks like std::string is the way to go.
Generally, the C++ sting is faster than coding it yourself. P.J. Plaugher, who wrote the template, has said: The template is optimized for speed. If you think you can do it faster, then think three times.
I know it's fun to write your own string functions because it's something you know how to do already. I urgently suggest you don't waste time on this. The C++ string is an industry standard making your code more supportable and less prone to bugs. Anything you write will be a one-off, probably not reusable in many programs and harder to understand for maintenance.
In this area also:
1) Do not use arrays. Use STL vectors.
2) Do not write a linked list. Use the STL list template
3) Do not write a stack. Use the STL stack.
4) Do not write, queues, deques, priority_queues .
5) Do not write trees. Use set, multiset, map, multimap.
6) Do not wrote a sort. Use the sort
7) Do not write loops where there are algorithms already written.
8) Buy a copy of Effective STL by Scott Meyers
9) etc...
Thanks for all and this forum for this clear cut solution for the usage of string.It helped me to make a big decision on string manipulation in the current project and the future also.
Thanks friends
Once more in the string problem... if the project is the server program and it requires high efficiency..... Is it still the C++ string is better?
I have a question for you. Let's pretend the C++ string class did not exist. What kind of code would you end up writing?
On further reflection, consider what you probably would end up doing. You would end up making a mini C++ string class, following all the good programming techniques like RAII and so on, right? But wait, there's this whole C++ STL library, and you might want to make your C++ string class compatible with that, so you can take advantage of the C++ standard library. Do you see where I'm going with my logic?
Moreover, you're sitting around debating possible benefits to having a formal string class instead of the base C char arrays. Step 1, get code to work. Let's see you get working code before you talk about performance.
Comment