A class that provides various string library functions including concatenation, comparison, indexing, sub-string extraction, assignment, and shifting.
This repository contains a C++ program that implements a custom string class called STRING
. The STRING
class provides several overloaded operators and member functions for performing various operations on strings.
Features
- String concatenation using the
+
operator - In-place string concatenation using the
+=
operator - Accessing individual characters using the
[]
operator - String equality and inequality comparison using the
==
and!=
operators - String comparison using the
>
and<
operators - Extracting sub-strings using the
()
operator - Assignment of one string to another using the
=
operator - Left shift and right shift operations to shift characters within the string
- Getting the size of the string
Usage
- Clone the repository or download the source code files.
- Compile the source code using a C++ compiler of your choice.
- Run the compiled executable file.
Code Explanation
- The
STRING
class is defined with various member functions and overloaded operators. - The constructor
STRING(char a[])
initializes the string with the provided character array. - The overloaded
+
operator (operator+
) performs string concatenation between twoSTRING
objects. - The overloaded
+=
operator (operator+=
) performs in-place string concatenation on aSTRING
object. - The overloaded
[]
operator (operator[]
) allows access to individual characters of the string. - The overloaded
==
operator (operator==
) compares twoSTRING
objects for equality. - The overloaded
!=
operator (operator!=
) compares twoSTRING
objects for inequality. - The overloaded
>
and<
operators (operator>
andoperator<
) compare twoSTRING
objects. - The overloaded
()
operator (operator()
) extracts a sub-string from aSTRING
object. - The overloaded
=
operator (operator=
) assigns oneSTRING
object to another. - The overloaded
<<
and>>
operators (operator<<
andoperator>>
) allow input and output ofSTRING
objects using stream operators. - The
sizeofarray
andsizeofstring
member functions are used to determine the size of character arrays and C++ strings, respectively. - The
main
function demonstrates the usage of theSTRING
class by performing various operations onSTRING
objects.
Contributing Contributions to the project are welcome. If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.