# VBForums CodeBank > CodeBank - C++ >  C++ - String Class remake (not all functions but most)

## g4hsean

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:



```
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);
};
```

----------


## g4hsean

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

----------

