Exemplo n.º 1
0
//-----------------------------------------------------
MyString MyString::operator+ (const MyString & aMyString)
{
	MyString Temp;
	Temp.Assign(*this);
	Temp.Append(aMyString);
	return Temp;
}
Exemplo n.º 2
0
//-----------------------------------------------------
MyString MyString::operator+ (const char *  const aCString)
{
	MyString Temp;
	Temp.Assign(*this);
	Temp.Append(aCString);
	return Temp;
}
Exemplo n.º 3
0
int main()
{
	MyString m;

	assertEqual(16, m.CurrentCapacity(), "Default ctor: sets capacity to 16");
	assertEqual(0, m.Length(), "Default ctor: sets length to 0");
	assertEqual("", m._cstr(), "Default ctor: sets string to empty string");


	m.Assign("Bob");
	cout << "capacity is " << m.CurrentCapacity() << endl;
	cout << "length is " << m.Length() << endl;
	cout << "string points to an ascii " << (m._cstr()) << endl;


	m.Assign("123456789012345678901234567890");

	assertTrue(m.CurrentCapacity() >= 30, "Assign('123456789012345678901234567890': capacity >= 30");
	assertEqual(30, m.Length(), "Assign('123456789012345678901234567890': sets length to 30");
	assertEqual("123456789012345678901234567890", m._cstr(), "Assign('123456789012345678901234567890')");
	char buffer[100] = "";


	cout << m << endl;
	cout << "Enter some text: ";
	cin >> m;
	cout << m << endl;

	MyString m2;
	cout << "Enter some text: ";
	cin >> m2;
	cout << m2 << endl;


	system("pause");
	return 0;
}
Exemplo n.º 4
0
	// Insert
		// Takes two arguments
		// An int – the index in this MyString
		//   at which to insert the new chars
		// A MyString containing the chars to be inserted
void MyString::Insert(const MyString & aMyString, int index) {
	if(index > _length)
		throw std::runtime_error("RAGEQUIT index is greater than Length()");
	if(index < 0)
		throw std::runtime_error("RAGEQUIT index is less than zero");
 
	MyString bMyString = aMyString;
 
	MyString returnString = MyString();
	MyString subString = MyString(SubStr(index, _length - index));
 
	returnString.Assign(SubStr(0, index));
	returnString.Append(bMyString);
	returnString.Append(subString);
 
	Assign(returnString);
 
}