Esempio n. 1
0
int main()
{
   // Define and initialize several MyString objects.
   MyString object1("This"), object2("is");
   MyString object3("a test.");
   MyString object4 = object1;  
   MyString object5("is only a test.");
   // Define a C-string.
   char string1[] = "a test.";

   // Display the MyString objects.
   cout << "object1: " << object1 << endl;
   cout << "object2: " << object2 << endl;
   cout << "object3: " << object3 << endl;
   cout << "object4: " << object4 << endl;
   cout << "object5: " << object5 << endl;

   // Display the C-string.
   cout << "string1: " << string1 << endl;

   // Test the overloaded += operator.
   object1 += " ";
   object1 += object2;
   object1 += " ";
   object1 += object3;
   object1 += " ";
   object1 += object4;
   object1 += " ";
   object1 += object5;
   cout << "object1: " << object1 << endl;

   return 0;
}
int main()
{
	MyString object1("This"), object2("is");
	MyString object3("a test.");
	MyString object4 = object1;
	MyString object5("is only a test");
	char string1[] = "a test.";

	std::cout << "Object1: " << object1 << std::endl;
	std::cout << "Object2: " << object2 << std::endl;
	std::cout << "Object3: " << object3 << std::endl;
	std::cout << "Object4: " << object4 << std::endl;
	std::cout << "Object5: " << object5<< std::endl;
	std::cout << "String 1:" << string1 << std::endl;
	object1 += " ";
	object1 +=object2;
	object1 += " ";
	object1 += object3;
	object1 += " ";
	object1 += object4;
	object1 += " ";
	object1 += object5;
	object1 += " ";
	std::cout << "object1: " << object1 << std::endl;

   return 0;
}