468,491 Members | 2,024 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,491 developers. It's quick & easy.

C++ string c string

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
Mar 4 '08 #1
10 3870
gpraghuram
1,275 Expert 1GB
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

Raghuram
Mar 4 '08 #2
first of all Thanks gpraghuram.

what about the memory size and memory allocations, speed of C++ string?
Is it affect the performance of program?

Is the string class overhead negligible when compared with the hassles of c memory allocation.

john
Mar 4 '08 #3
gpraghuram
1,275 Expert 1GB
first of all Thanks gpraghuram.

what about the memory size and memory allocations, speed of C++ string?
Is it affect the performance of program?

Is the string class overhead negligible when compared with the hassles of c memory allocation.

john
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

Raghuram
Mar 4 '08 #4
Banfa
9,055 Expert Mod 8TB
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.
Mar 4 '08 #5
Ganon11
3,652 Expert 2GB
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.
Mar 4 '08 #6
weaknessforcats
9,207 Expert Mod 8TB
Use the C++ string.

All of the C-string library is deprecated in C++.

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...
Mar 4 '08 #7
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.


John
Mar 5 '08 #8
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?

john
Mar 5 '08 #9
oler1s
671 Expert 512MB
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.
Mar 5 '08 #10
Thanks for the answer.
Definitely a new "our own string class" is not a feasible one.

John
Mar 5 '08 #11

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

16 posts views Thread by Krakatioison | last post: by
5 posts views Thread by Stu Cazzo | last post: by
9 posts views Thread by John F Dutcher | last post: by
10 posts views Thread by Angus Leeming | last post: by
2 posts views Thread by Andrew | last post: by
29 posts views Thread by zoro | last post: by
2 posts views Thread by Badass Scotsman | last post: by
15 posts views Thread by morleyc | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
reply views Thread by theflame83 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.