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
10 4150 gpraghuram 1,275
Recognized Expert Top Contributor
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
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
gpraghuram 1,275
Recognized Expert Top Contributor
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
Banfa 9,065
Recognized Expert Moderator Expert
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.
Ganon11 3,652
Recognized Expert Specialist
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.
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...
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
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
oler1s 671
Recognized Expert Contributor
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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... this number is always changing as I have hundreds of
thousand of pages of text on my site.
Problem:
- in my opinion this just not only look weird, but the variable "n" (number)
|
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 will split myString up using the delimiter of 1 space
so that
|
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., etc.
The intent is to finish by assigning the list to a string that I would
write to disk: recstr = string.join(recd,'')
|
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 effectively impossible to forward declare
std::string. (Yes I am aware that some libraries have a string_fwd.h header,
but this is not portable.)
That said, is there any real reason why I can't derive an otherwise empty
|
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
| |
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 substring
before a pattern), AFTER (return substring after a pattern), and
BETWEEN (return substring between 2 patterns).
My questions are:
1. Can any tell me how I can implement such functionality in C#?
2. Is it possible to add/include function...
|
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 a tasty burger"
|
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
|
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 spaces, but not in the inner
string(\"and a inner string\\\"). Will anyone please tell me how to do
this?
|
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 add the unique words in the string to a map. Eg:
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |