answersLogoWhite

0


Best Answer

I assume you mean std::string rather than strings in general. Programs that need to convey any information to the user will usually require many strings, and when retreiving input from the user, a string (in conjunction with a string stream) are the best way of checking that data before processing it. The std::string (and its wide-character counterpart, std::wstring) needn't be used for all strings, of course, but they are much easier to work with when strings need additional processing, such as when concatenating strings, or searching within strings. And if you need more functionality than is provided by std::string alone, you can always derive a new string object from std::string and embelish it as required. Of course, if you require less functionality than is provided by std::string then you have the option of creating your own lightweight string class from scratch. However, for most applications, std::string is lightweight enough, and if you use std::string at all, then there's little point in writing your own string class. Aside from re-inventing the wheel (one of the reasons the STL exists), it's only going to increase your code size. However, for new programmers, it can be an interesting excercise creating your own string class, if only to show how std::string works and why re-inventing wheels is rarely a good thing.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

just chill guys listen raps

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are the advantages of using string in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How can you get a specific string from large string using c plus plus strings?

std::string::substr();


What is the program to create a string class which stores a string value in c plus plus?

C++ already provides a string class in the C++ standard template library. #include<iostream> #include<string> int main() { using namespace std; string s {"Hello world!"}; cout << s << endl; }


Why can't the c plus plus compiler find the string object?

The most likely reason that the C++ compiler can't find the string object is just that you've forgotten to include the string header file.Code Example:#include // so you can use C++ strings using namespace std; // so you can write 'string' instead of 'std::string' string sMyString; // declare a string


How do you store a string in c plus plus?

#include <iostream> #include <string> using std::cout; using std::cin; using std::string; using std::getline; using std::endl; int main() { string myString = ""; cout << "Enter your string: "; getline(cin, myString, '\n'); cout << "\nYou have entered - " << myString << endl; system("PAUSE"); return 0; }


What is the difference between a C plus plus string and a C-style string?

A std::string is an object that encapsulates an array of type char whereas a C-style string is a primitive array with no members. A std::string is guaranteed to be null-terminated but a C-style string is not.


C plus plus code to find the length of a string without using function?

int i = 0; while(str[i] != NULL){ i++; }


Is there a datatype string in c plus plus?

Yes.


C plus plus library functions for string operations?

You can use "string" class in C++ for string operations or you may use c style string functions as well. #include <string> String class in C++ provides all basic function to operate on strings. you may details descriptin at http://www.cplusplus.com/reference/string/string/


What is the role of plus operator between two string constant?

The plus operator between string constants allows string concatination: string a = "Hello, "; string b = "World!"; string c = a + b; The output of c would be: "Hello, World!".


How will you create a string in c plus plus?

#include <string> #include <iostream> using namespace::std; ... string str = "This is a test"; cout << str << endl; str = "This is also a test"; cout << str << endl; Gives you ... This is a test This is also a test


Advantages of manipulator in c plus plus?

theriyadhu


Function in C plus plus that takes in any number parameter and returns the string representation of it?

#include#includeusing std::cin;using std::cout;using std::endl;using std::string;int main(){string number = "0";cout number;cout