C++ String Class

Screen print of code
This is a simple string class that I constructed as an assignment for one of my classes. Most programmers would just use C++'s built in string preprocessor, but it's a good exercise because in some cases you may need to write your own to serve your specific needs.
#include 
using namespace std;
 
class String {
private:
    char* strval;     //holds string value
    int strln;           //holds length of string value
public:
    //constructors
    String();           //initializes default value of null string
    String(char* s);   //initiializes string to value of cstring s
 
 //destructor
 ~String();   
 
    //access functions
    bool operator==(const String s);   //true if value equal to s, else false
    bool operator(const String s);   //true if value greater than s, else false
    int length();                      //returns length of string value
/*    String operator+(String s); */    //returns concatenation of s to string value
 
    //modifier functions
    void tolowercase();
 
    //input/output functions
    //reads in string value from istream
    friend istream& operator>>(istream &strm, String &strng);
    //outputs string value to ostream
    friend ostream& operator<(String s)    //true if value greater than s, else false
{
    int shorter_len = ((strlns.strval[i]))
        return_value = true;
    else
        if ((i==s.strln) && (strln>s.strln))
            return_value = true;
    return return_value;
}
 
int String::length()
 {return strln;}
 
istream& operator>>(istream& strm, String& strng)
{
 char* temp = new(char[101]);
    strm >> temp;
    for (strng.strln=0; strng.strln < strlen(temp); strng.strln++)
 {
        *(strng.strval+strng.strln) = *(temp+strng.strln);
 }
    return strm;
 delete [] temp;
}
 
ostream& operator<> s1;
 
}
Posted in C++

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">