C++ - String Class remake (not all functions but most)-VBForums
Results 1 to 2 of 2

Thread: C++ - String Class remake (not all functions but most)

  1. #1

    Thread Starter
    Hyperactive Member g4hsean's Avatar
    Join Date
    May 2006
    Posts
    267

    Post C++ - String Class remake (not all functions but most)

    Hello everyone!

    I have created this code for fun to help people understand the basic functionality of the string class. I have named my verion the Vstring class since i dont want people getting confused with the two. I have also added unit testing to this project to allow people to understand how amazing asserts come in handy in producing code with minimum errors. As you will see there is a lot of emphasis on the object oriented approach so please understand objects pointers and references before downloading.

    Class decleration:

    Code:
    static const signed short int V_STRING_ARRAY_MAX = 32767; // used for input stream
    class Vstring
    {
    public:
    	Vstring(void);
    	Vstring(const Vstring& s);
    	Vstring(const char* stri);
    	~Vstring(void);
    
    	Vstring& operator=(const Vstring& rhs);
    	Vstring operator+(const Vstring& rhs);
    	bool operator==(const Vstring& rhs);
    	bool operator!=(const Vstring& rhs);
    	bool operator<(const Vstring& rhs);
    	bool operator >(const Vstring& rhs);
    	bool operator >=(const Vstring& rhs);
    	bool operator <=(const Vstring& rhs);
    	
    	friend ostream& operator<< (ostream& os, const Vstring& str);
    	friend istream& operator>> (istream& is, Vstring& str);
    
    	const char at( int pos )const;
    	
    	const char* c_str();
    	
    	void clear();
    	
    	bool empty() const;
    	
    	Vstring& erase(int index = 0, int size = 0);
    	
    	int find ( const Vstring& str, int pos = 0 ) const;
    	int find ( const char* str, int pos = 0 );
    	
    	Vstring& insert( int pos1, const Vstring& str );
    	Vstring& insert( int pos1, const char* s );
    	
    	int length() const;
    	
    	const int max_size() const;
    	
    	Vstring& replace ( int index, int size, const Vstring& str );
    	Vstring& replace(int pos1, int n1, const char* str);
    	
    	int size() const;
    	
    	void swap ( Vstring& str );
    	void swap ( char* str );
    
    private:
    	int VstringLen;
    	char* VstringArray;
    	char* c_strArray;
    	int c_strLength(const char* c_str);
    };
    Coding's a Breeze if you'r at ease! GOD THATS CORNY!!
    -

  2. #2

    Thread Starter
    Hyperactive Member g4hsean's Avatar
    Join Date
    May 2006
    Posts
    267

    Post Re: C++ - String Class remake (not all functions but most)

    As you can see there is only one global variable. Which I advise to replace if you want to use this class since the use of global variables is somewhat bad coding practice.

    To use these classes all you have to do is import the .cpp files and header files into your project (assuming Visual Studio) and compile it into your application. Once thatís done you are up and running and can use the class as you would like.

    I hope this fun exercise can help you familiarize yourself with C++ and many of its implementations.

    Please feel free to use the code anywhere, and if there are any questions or suggestions please donít hesitate to send me a message!

    Click attachment for all Vstring files
    Attached Files Attached Files
    Coding's a Breeze if you'r at ease! GOD THATS CORNY!!
    -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.