Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there a different string class in every C++ platform out there?

While I like programming in C++, I hate the idea of:
std::basic_string vs QString vs wxString vs .............
Doesn't the standard string class satisfy the needs for these frameworks? I mean what is wrong with the standard string class?!

Just to emphasize, that below is the important question:
Do you learn "the" string class of the framework in every framework you are going to work with? would you instead stick to the standard string class by trying to adapt it everywhere?

Thanks...

like image 993
Khaled Alshaya Avatar asked Oct 24 '09 19:10

Khaled Alshaya


People also ask

Can you point out the main difference between C C++ strings and Java strings?

String in Java is slower when modified as compared to the StringBuffer class. C++ string class in STL are slower in implementation than Strings declared using character array. Strings are faster in implementations as compared to the String class of C++. Memory allocation is static as strings are immutable.

What is the use of string class explain any five functions of string class?

Java String class provides a lot of methods to perform operations on strings such as compare(), concat(), equals(), split(), length(), replace(), compareTo(), intern(), substring() etc. The java.lang.String class implements Serializable, Comparable and CharSequence interfaces.

What is the use of string class?

The String class represents character strings. All string literals in Java programs, such as "abc" , are implemented as instances of this class. Strings are constant; their values cannot be changed after they are created.

Is string a class C#?

A string is not a data type but a class in System namespace in C# i.e., System. String and string is an alias (another name) of the same.


2 Answers

The reason for multiple string classes is that the C++ standard was finalized fairly late (in 1998); it then took some time until all systems actually provided a correct C++ library. By that time, all these competing string classes where already written.

In addition, in some cases, people want to inherit from a single base class, which std::string wouldn't do.

like image 121
Martin v. Löwis Avatar answered Oct 05 '22 06:10

Martin v. Löwis


IMO, std::string isn't old enough to be widespread (Qt and wxWidgets are older than the STL, or at least older than widely available stable and working STLs). Also, std::string is sadly not the best string class there is for everyone, and other frameworks have other needs.

Note! The paragraph below slightly incorrect, but kept to make sense of comments.

For instance, C++ STL's is very resource constrained, whereas the Qt string class offer lots of goodies that a committe would never agree on, especially as some want it to be easily implementable on embedded systems and the like.

like image 36
Macke Avatar answered Oct 05 '22 06:10

Macke