< Prev
Next >



String class in C++






Apart from allowing us to create c-style strings by using char arrays, C++ provides us a string class using which we can easily create string objects. String is a nothing but a sequence of characters within double quotes. For example - "Hello World" is a string literal, using it we can create a string object of string class.




Constructors of string class


There are about three constructors of string class, providing it multiple ways by which we could create string objects. Let us see these constructors.

Constructor Description
string()
This constructor is used to create an empty string object.

string(const string & str)
This constructor is used to create a string object, by passing a string object to it. The new string object is initialized with the content of the passed string object.

string(const char *st)
This constructor is used to create a string object, by passing a char array to it. The new string object is initialized with the content of the passed char array.






How a String object is created?


In C++, a string object can be constructed in various ways as explained below -:

Please subscribe our social media channels for notifications, we post a new article everyday.

Decodejava Google+ Page Decodejava Facebook Page  DecodeJava Twitter Page

Coming Next
-
Python

Ad2