473,231 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

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 4114
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,065 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,208 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

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

Similar topics

16
by: Krakatioison | last post by:
My sites navigation is like this: http://www.newsbackup.com/index.php?n=000000000040900000 , depending on the variable "n" (which is always a number), it will take me anywhere on the site......
5
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
9
by: John F Dutcher | last post by:
I use code like the following to retrieve fields from a form: recd = recd.append(string.ljust(form.getfirst("lname",' '),15)) recd.append(string.ljust(form.getfirst("fname",' '),15)) etc.,...
10
by: Angus Leeming | last post by:
Hello, Could someone explain to me why the Standard conveners chose to typedef std::string rather than derive it from std::basic_string<char, ...>? The result of course is that it is...
2
by: Andrew | last post by:
I have written two classes : a String Class based on the book " C++ in 21 days " and a GenericIpClass listed below : file GenericStringClass.h // Generic String class
29
by: zoro | last post by:
Hi, I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party string handling library that includes some very useful string functions, in particular I'm interested in BEFORE (return...
2
by: Badass Scotsman | last post by:
Hello, Using VB and ASP,NET I would like to be able to search a STRING for a smaller STRING within, based on the characters which appear before and after. For example: String1 = " That was...
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
11
by: ramu | last post by:
Hi, Suppose I have a string like this: "I have a string \"and a inner string\\\" I want to remove space in this string but not in the inner string" In the above string I have to remove...
8
by: drjay1627 | last post by:
hello, This is my 1st post here! *welcome drjay* Thanks! I look answering questions and getting answers to other! Now that we got that out of the way. I'm trying to read in a string and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.