1 Replies - 2264 Views - Last Post: 16 February 2011 - 07:03 PM Rate Topic: -----

#1 boxchamp  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 78
  • Joined: 22-November 10

Custom string class

Posted 16 February 2011 - 06:20 PM

hey everyone. i have a problem i am working on and i am completely lost. i cant seem to get these advanced topics. i am trying to recreate the string class without using the string.h file. i am supposed to fill in the functions but am completely lost so i need some help brainstorming ideas. how would a professional go through someone else's code and figure out where to start. i am not allowed to touch the driver.cpp. i know what every function does but dont know how to recreate them. here is the code. oh so far i have tried to isolate the code in blocks to try and see what works and what doesnt. i get this strange error that i cant figure out. since this is a really big program can you give me advice on how to go about the first three functions. not answers i just want brainstorming ideas please so i can learn.

here is that error code:

mt.exe : general error c101008a: Failed to save the updated manifest to the file "Debug\MyString.exe.embed.manifest". The parameter is incorrect.
1>

// MyString.h
// MyString is a custom string class implementation.
// insure that this header file is not included more than once 
#pragma once
#ifndef MYSTRING_H_
#define MYSTRING_H_
#include <iostream>
using std::ostream;
using std::istream;

class MyString
{
private:
      int _capacity; // current number of chars allocated
      int _length; // current length of string
      char * _string; // ptr to allocated chars
public:

// CONSTRUCTORS

      // default constructor

            // initializes _capacity to 16 chars

            // initializes this MyString to an empty MyString
      MyString();
      // parameterized constructors

            // takes a c style string argument

            // initializes capacity to greater of strlen(cString) or 16 chars

            // initializes this MyString to cString

      MyString(const char * aCString);
            // takes an int argument
            // initializes capacity to numChars chars
            // initializes this MyString to an empty MyString
      MyString(int numChars);
      // copy constructor
	  
            // initializes this MyString to a deep copy of the original
      MyString(const MyString & original);
// DESTRUCTOR

            // dealocate dynamic storage
      ~MyString();

// METHODS

      // Append 
            // Takes a MyString argument 
            // Appends chars to the end of this MyString 
      void Append(const MyString & aMyString);
            // Takes  a c style string argument 
            // Appends chars to the end of this MyString 
      void Append(const char * aCString);
      // Assign 
            // Takes a MyString argument 
            // makes this MyString a copy of aMyString
      void Assign(const MyString & aMyString);
            // Takes  a c style string argument
            // makes this MyString contain the chars of aCString
      void Assign(const char * const aCString);

	  /////////////////////////////////////////////////////////////////
	  /*
      // At 
            // Takes an int argument 
            // Returns a copy of the char at that index
            // throws an exception if index is < 0 or >= _length
      char At(int index) const;
	  */
      // Clear 
            // Makes this MyString empty 
            // does not change capacity;
      void Clear();
            // Makes this MyString empty 
            // changes capacity to newCapacity
            // throws an exception if newCapacity < 0
      void Clear(int newCapacity);
	  /*
      // Compare 
            // Takes a MyString argument 
            // Returns (zero) if the argument contains 
//   the same string of chars as this MyString 
            // Returns (a positive int) if the argument is 
//   alphabetically less than this MyString 
            // Returns (a negative int) if the argument is 

//   alphabetically greater than this MyString 

      int Compare(const MyString & aMyString);
      // Equals 
            // Takes a MyString argument 
            // Returns (true) if the argument contains 
//   the same string of chars as this MyString, 
//   otherwise it returns (false). 
      bool Equals(const MyString & aMyString) const;
            // Takes a c style string argument 
            // Returns (true) if the argument contains 
//   the same string of chars as this MyString, 
//   otherwise it returns (false). 
      bool Equals(const char * const aCString) const;

 

      // Find 

            // Takes a myString argument 

            // Returns the index (int) 

//   where the argument MyString was found 

//   in this MyString. If it is not found, then returns -1. 

      int Find(const MyString & aMyString) const;

 

      // 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 Insert(const MyString & aMyString, int index);

 

      // Length 

            // Returns the number (int) of chars in this MyString 

      int Length(void) const;

 

      // Replace 

            // Takes three arguments 

            // An int  the index of the char in thisMyString 

//   to begin replacing at. 

            // An int  the number of chars to replace 

            // And a MyString containg the replacement string 

            // throws an exception if startIndex >= Length

            // throws an exception if startIndex + numChars > Length()

            // throws an exception if aMyString.Length() < numChars

      void Replace(int startIndex, int numChars, const MyString & aMyString);

 

      // Substr 

            // Takes two int arguments, 

            // An int for the starting index, 

            // An int for the number of chars to return. 

            // Returns a MyString with the requested sub-string 

//   from the original MyString 

            // throws an exception if startIndex + numChars > Length()

      MyString SubStr(int startIndex, int numChars) const;

 

// OPERATORS

 

      // = (assignment - takes a MyString or a c style string) 

      MyString operator= (const MyString & aMyString);

      MyString operator= (const char *  const aCString);

 

      // +, += (concatenation - takes a MyString or a c style string) 

      MyString operator+ (const MyString & aMyString);

      MyString operator+= (const MyString & aMyString);

 

      // [] (read/write char access by index) 

            // Returns a reference to the char at that index

            // throws an exception if index is < 0 or >= _length

      char & operator[] (int index) const;

 

      // >, <, >=, <=, ==, != (boolean relational test operators) 

      bool operator> (const MyString & aMyString) ;

      bool operator< (const MyString & aMyString) ;

      bool operator>= (const MyString & aMyString) ;

      bool operator<= (const MyString & aMyString) ;

      bool operator== (const MyString & aMyString) ;

      bool operator!= (const MyString & aMyString) ;

 */

      // <<, >> stream insertion and extraction

      friend ostream & operator<< (ostream & os, const MyString & aMyString);

 

      friend istream & operator>> (istream & is, MyString & aMyString);
	  

};

#endif





// MyString.cpp
#include "MyString.h"
#include <cstring>

// private:
//	int _capacity; // current number of chars allocated
//	int _length; // current length of string
//	char * _string; // ptr to allocated chars

// CONSTRUCTORS
// default constructor
// inits _capacity to 16 chars
// inits this MyString to an empty MyString
MyString::MyString()
{
	_capacity = 16;
	_string = new char[_capacity+1];
	_length = 0;
	memset(_string, 0, _capacity+1);
}

// parameterized constructors
// takes a c style string argument
// inits capacity to greater of strlen(cString) or 16 chars
// inits this MyString to cString
MyString::MyString(const char * aCString)
{	
	_length = (int)strlen(aCString);
	_capacity = _length <= 16 ? 16 : _length;
	_string = new char [_capacity+1];

	memset(_string, 0, _capacity+1);
	memcpy(_string, aCString, _length);
}
// takes an int argument
// inits capacity to numChars chars
// inits this MyString to an empty MyString
MyString::MyString(int numChars)
{	
	_capacity = numChars;
	_string = new char [_capacity+1];
	_length = 0;
	memset(_string, 0, _capacity+1);
}

// copy constructor
// inits this MyString a deep copy of the original
MyString::MyString(const MyString & original)
{
	_capacity = original._capacity;
	_length = original._length;
	_string = new char[_capacity+1];
	memset(_string, 0, _capacity+1);
	memcpy(_string, original._string, _length);
}

// DESTRUCTOR
// dealocate dynamic storage
MyString::~MyString()
{
	_length = 0;
	_capacity = 0;
	delete[] _string;
	_string = NULL;
}

// METHODS
// Append 
// Takes a MyString argument 
// Appends chars to the end of this MyString 
void MyString::Append (const MyString & aMyString)
{
	if((_length + aMyString._length) > _capacity) {			
		_capacity = _length + aMyString._length;
		char *buffer = new char[_length + aMyString._length+1];
		memset(buffer, 0, _capacity+1);
		memcpy(buffer, _string, _length);
		delete[] _string;
		_string = buffer;
	}

	memcpy(_string + _length, aMyString._string, aMyString._length);
	_length += aMyString._length;


}



// Takes  a c style string argument 
// Appends chars to the end of this MyString 
void MyString::Append(const char * const aCString)
{
	int stringlength = strlen(aCString);
	if((_length + stringlength) > _capacity) {
		_capacity = _length + stringlength;
		char *buffer = new char[_length + stringlength+1];
		memset(buffer, 0, _capacity+1);
		memcpy(buffer, _string, _length);
		delete[] _string;
		_string = buffer;
	}

	memcpy(_string + _length, aCString, stringlength);
	_length += stringlength;
}

// Assign 
// Takes a MyString argument 
// makes this MyString a copy of aMyString
void MyString::Assign(const MyString & aMyString)
{
	if(_capacity < aMyString._length)
		Clear(aMyString._length);

	memcpy(_string, aMyString._string, aMyString._length);
	_length = aMyString._length;
	_string[_length] = 0;

}
// Takes  a c style string argument 
// makes this MyString contain the chars of aCString
void MyString::Assign(const char * const aCString)
{
	if(_string != NULL)
		delete[] _string;

	_length = strlen(aCString);
	_capacity = _length < 16 ? 16 : _length;

	_string = new char[_capacity+1];
	memset(_string, 0, _capacity+1);
	memcpy(_string, aCString, _length);
}

/////////////////////////////////////////////////////////
/*
// At 
// Takes an int argument 
// Returns a copy of the char at that index
// throws an exception if index is < 0 or >= _length
char MyString::At(int index) const
{
	if(index < 0 || index >= _length)
		throw std::out_of_range("MyString::At");

	return *(_string + index);

}
*/
// Clear 
// Makes this MyString empty 
// does not change capacity;
void MyString::Clear()
{
	if(_string != NULL)
		delete[] _string;

	_string = new char[_capacity+1];
	memset(_string, 0, _capacity+1);
	_length = 0;
}
// Makes this MyString empty 
// changes capacity to newCapacity
// throws an exception if newCapacity < 0
void MyString::Clear(int newCapacity)
{	
	if(newCapacity < 0)
		throw std::invalid_argument("My String::Clear");

	if(_string != NULL)
		delete[] _string;

	_capacity = newCapacity;
	_string = new char[_capacity+1];
	memset(_string, 0, _capacity+1);
	_length = 0;
}
/*
// Compare 
// Takes a MyString argument 
// Returns (zero) if the argument contains the same string of chars as this MyString 
// Returns (a positive int)  if the argument is alphabetically less than this MyString 
// Returns (a negative int)  if the argument is alphabetically greater than this MyString 
int MyString::Compare(const MyString & aMyString)
{	
	return strcmp(_string, aMyString._string);
}

// Equals 
// Takes a MyString argument 
// Returns (true) if the argument contains the same string of chars as this MyString, otherwise it returns (false). 
bool MyString::Equals(const MyString & aMyString) const
{	
	return (strcmp(_string, aMyString._string) == 0);
}
// Takes a c style string argument 
// Returns (true) if the argument contains the same string of chars as this MyString, otherwise it returns (false). 
bool MyString::Equals(const char * const aCString) const
{	
	return (strcmp(_string, aCString) == 0);
}

// Find 
// Takes a myString argument 
// Returns the index (int) where the argument MyString was found in this MyString. If it is not found, then returns -1. 
int MyString::Find(const MyString & aMyString) const
{	
	if(_length <= 0 || aMyString._length <=0)
		return -1;

	char* subString = strstr(_string, aMyString._string);
	if(subString == NULL)
		return -1;

	return subString - _string;
}

// 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(aMyString._length <=0)
		return;

	if(_length + aMyString._length > _capacity){
		_capacity  = _length + aMyString._length;
		char *buffer = new char[_capacity+1];
		memset(buffer, 0, _capacity+1);
		memcpy(buffer, _string, _length);
		delete[] _string;
		_string = buffer;
	}
	memcpy(_string + index + aMyString._length, _string + index, _length - index);
	memcpy(_string + index, aMyString._string, aMyString._length);
	_length += aMyString._length;
}

// Length 
// Returns the number (int) of chars in this MyString 
int MyString::Length(void) const
{
	return _length;
}

// Replace 
// Takes three arguments 
// An int  the index of the char in thisMyString to begin replacing at. 
// An int  the number of chars to replace 
// And a MyString containg the replacement string 
// throws an exception if startIndex >= Length
// throws an exception if startIndex + numChars > Length()
// throws an exception if aMyString.Length() < numChars
void MyString::Replace(int startIndex, int numChars, const MyString & aMyString)
{
	if(startIndex < 0 || startIndex > _length || startIndex + numChars > _length || aMyString._length < numChars)
		throw std::invalid_argument("MyString::Replace");

	memcpy(_string + startIndex, aMyString._string, numChars);
}

// Substr 
// Takes two int arguments, 
// An int for the starting index, 
// An int for the number of chars to return. 
// Returns a MyString with the requested sub-string from the original MyString 
// throws an exception if startIndex + numChars > Length()
MyString MyString::SubStr(int startIndex, int numChars) const
{
	if(startIndex + numChars > _length)
		throw std::invalid_argument("MyString::Substr");

	char *buffer = new char[numChars+1];
	
	memcpy(buffer, _string+startIndex, numChars);
	buffer[numChars] = 0;
	MyString newString(buffer);
	delete[] buffer;
	return newString;
}

// OPERATORS

// = (assignment - takes a MyString or a c style string) 
MyString MyString::operator= (const MyString & aMyString)
{
	Assign(aMyString);
	return *this;
}
MyString MyString::operator= (const char *  const aCString)
{
	Assign(aCString);
	return *this;
}

// +, += (concatenation - takes a MyString or a c style string) 
MyString MyString::operator+ (const MyString & aMyString)
{
	Append(aMyString);
	return *this;
}
MyString MyString::operator+= (const MyString & aMyString)
{
	Append(aMyString);
	return *this;
}

// [] (read/write char access by index) 
//	 Returns a copy of the char at that index
//	 throws an exception if index is < 0 or >= _length
char & MyString::operator[] (int index) const
{
	if(index < 0 || index >= _length)
		throw std::out_of_range("MyString::operator[]");

	return *(_string+index);
}


// >, <, >=, <=, ==, != (boolean relational test operators) 
bool MyString::operator> (const MyString & aMyString) 
{
	return Compare(aMyString) > 0;
}
bool MyString::operator< (const MyString & aMyString) 
{
	return Compare(aMyString) < 0;
}
bool MyString::operator>= (const MyString & aMyString) 
{
	return Compare(aMyString) >= 0;
}
bool MyString::operator<= (const MyString & aMyString) 
{
	return Compare(aMyString) <= 0;
}
bool MyString::operator== (const MyString & aMyString) 
{
	return Equals(aMyString);
}
bool MyString::operator!= (const MyString & aMyString) 
{
	return !Equals(aMyString);
}
*/
// <<, >> stream insertion and extraction
ostream & operator<< (ostream & os, const MyString & aMyString)
{
	os << aMyString._string;
	return os;
}

istream & operator>> (istream & is, MyString & aMyString)
{	
	char *buffer = new char[1024];
	is.getline(buffer, 1024);
	if(is.gcount() > 0)
	{
		aMyString.Clear(is.gcount());
		aMyString.Assign(buffer);
	}
	else
		aMyString.Clear();

	return is;
}


#include <iostream>
#include "MyString.h"

using namespace std;

int main()
{
	
	cout << "=== CONSTRUCTORS ===================================\n\n";

	cout << " >>> MyString s1;\n";
	MyString s1;

	cout << " >>> MyString s2(\"abc 123\");\n";
	MyString s2("abc 123");

	cout << " >>> MyString s3(10);\n";
	MyString s3(10);

	cout << " >>> MyString s4(s2);\n";
	MyString s4(s2);

	cout << "\n s1 = [" << s1 << "]\n";
	cout <<   " s1 = [] ***\n\n";
	cout <<   " s2 = [" << s2 << "]\n";
	cout <<   " s2 = [abc 123] ***\n\n";
	cout <<   " s3 = [" << s3 << "]\n";
	cout <<   " s3 = [] ***\n\n";
	cout << " s4 = [" << s4 << "]\n";
	cout <<   " s4 = [abc 123] ***\n\n\n";

	cout << "=== METHODS ========================================\n";

	cout << "\n--- APPEND -----------------------------------------\n\n";

	s1 = "";
	s2 = "abc 123";
	s3 = "";
	s4 = "abc 123";

	cout << " s1 = [" << s1 << "]\n";
	cout << " s2 = [" << s2 << "]\n";
	cout << " s3 = [" << s3 << "]\n";
	cout << " s4 = [" << s4 << "]\n\n";

	s1.Append("xyz");
	cout << " >>> s1.Append(\"xyz\");                    s1 = [" << s1 << "]\n";
	cout << "                                               [xyz] ***\n\n";
	s1.Append("");
	cout << " >>> s1.Append(\"\");                       s1 = [" << s1 << "]\n";
	cout << "                                               [xyz] ***\n\n";
	s2.Append(s1);
	cout << " >>> s2.Append(s1);                s2 = [" << s2 << "]\n";
	cout << "                                        [abc 123xyz] ***\n\n";
	s3.Append("12345678901234567890");
	cout << " >>> s3.Append(\"12345678901234567890\");\n";
	cout << "                         s3 = [" << s3 << "]\n";
	cout << "                              [12345678901234567890] ***\n\n";
	s4.Append(s4);
	cout << " >>> s4.Append(s4);            s4 = [" << s4 << "]\n";
	cout << "                                    [abc 123abc 123] ***\n\n";

	cout << "\n--- ASSIGN -----------------------------------------\n\n";

	s1 = "xyz";
	s2 = "abc 123xyz";
	s3 = "12345678901234567890";
	s4 = "abc 123abc 123";

	cout << " s1 = [" << s1 << "]\n";
	cout << " s2 = [" << s2 << "]\n";
	cout << " s3 = [" << s3 << "]\n";
	cout << " s4 = [" << s4 << "]\n\n";

	s1.Assign(s2);
	cout << " >>> s1.Assign(s2);                  s1=[" << s1 << "]\n";
	cout << "                                        [abc 123xyz] ***\n\n";
	s2.Assign("pink pony");
	cout << " >>> s2.Assign(\"pink pony\");        s2 = [" << s2 << "]\n";
	cout << "                                         [pink pony] ***\n\n";
	s3.Assign(s3);
	cout << " >>> s3.Assign(s3);      s3 = [" << s3 << "]\n";
	cout << " >>> s3.Assign(s3);           [12345678901234567890] ***\n\n";
	s4.Assign("");
	cout << " >>> s4.Assign(\"\");                          s4 = [" << s4 << "]\n";
	cout << "                                                  [] ***\n\n";

	////////////////////////////////////////////////////////////////////////
	/*
	cout << "\n--- AT ---------------------------------------------\n\n";

	s1 = "abc 123xyz";

	cout << " s1 = [" << s1 << "]\n\n";

	cout << " >>>                                  s1.At(4) = [" << s1.At(4) << "]\n";
	cout << "                                                 [1]\n";
	*/
	cout << "\n--- Clear ------------------------------------------\n\n";

	s1 = "abc 123xyz";
	s2 = "pink pony";

	cout << " s1 = [" << s1 << "]\n";
	cout << " s2 = [" << s2 << "]\n\n";

	s1.Clear();
	cout << " >>> s1.Clear();                             s1 = [" << s1 << "]\n";
	cout << "                                                  []\n";
	s2.Clear(10);
	cout << " >>> s2.Clear(10);                           s2 = [" << s2 << "]\n";
	cout << "                                                  []\n";
	/*
	cout << "\n--- Compare ----------------------------------------\n\n";

	s1 = "";
	s2 = "";
	s3 = "12345678901234567890";
	s4 = "";

	cout << " s1 = [" << s1 << "]\n";
	cout << " s2 = [" << s2 << "]\n";
	cout << " s3 = [" << s3 << "]\n";
	cout << " s4 = [" << s4 << "]\n\n";

	cout << " >>>                            s1.Compare(s2) = [" << s1.Compare(s2) << "]\n";
	cout << "                                                 [0] ***\n\n";
	cout << " >>>                            s3.Compare(s4) = [" << s3.Compare(s4) << "]\n";
	cout << "                                                 [1] ***\n\n";
	cout << " >>>                           s4.Compare(s3) = [" << s4.Compare(s3) << "]\n";
	cout << "                                                [-1] ***\n\n";
	cout << " >>>                            s4.Compare(s4) = [" << s4.Compare(s4) << "]\n";
	cout << "                                                 [0] ***\n\n";
	cout << " >>>        s3.Compare(\"12345678901234567890\") = [" << s3.Compare("12345678901234567890") << "]\n";
	cout << "                                                 [0] ***\n\n";

	cout << "\n--- Equals -----------------------------------------\n\n";

	s1 = "";
	s2 = "";
	s3 = "12345678901234567890";
	s4 = "";

	cout << " s1 = [" << s1 << "]\n";
	cout << " s2 = [" << s2 << "]\n";
	cout << " s3 = [" << s3 << "]\n";
	cout << " s4 = [" << s4 << "]\n\n";

	cout << " >>>                             s1.Equals(s2) = [" << s1.Equals(s2) << "]\n";
	cout << "                                                 [1] ***\n\n";
	cout << " >>>                             s3.Equals(s4) = [" << s3.Equals(s4) << "]\n";
	cout << "                                                 [0] ***\n\n";
	cout << " >>>                             s4.Equals(s4) = [" << s4.Equals(s4) << "]\n";
	cout << "                                                 [1] ***\n\n";
	cout << " >>>         s3.Equals(\"12345678901234567890\") = [" << s3.Equals("12345678901234567890") << "]\n";
	cout << "                                                 [1] ***\n\n";

	cout << "\n--- Find -------------------------------------------\n\n";

	s3 = "12345678901234567890";
	s4 = "";

	cout << " s3 = [" << s3 << "]\n";
	cout << " s4 = [" << s4 << "]\n\n";

	cout << " >>>                            s3.Find(\"456\") = [" << s3.Find("456") << "]\n";
	cout << "                                                 [3] ***\n\n";
	cout << " >>>                              s3.Find(s4) = [" << s3.Find(s4) << "]\n";
	cout << "                                                [-1] ***\n\n";
	cout << " >>>                               s3.Find(s3) = [" << s3.Find(s3) << "]\n";
	cout << "                                                 [0] ***\n\n";
	cout << "\n--- Insert -----------------------------------------\n\n";

	s1 = "";
	s2 = "";
	s3 = "12345678901234567890";
	s4 = "";

	cout << " s1 = [" << s1 << "]\n";
	cout << " s2 = [" << s2 << "]\n";
	cout << " s3 = [" << s3 << "]\n";
	cout << " s4 = [" << s4 << "]\n\n";

	s1.Insert("xxx", 0);
	cout << " >>> s1.Insert(\"xxx\", 0);                 s1 = [" << s1 << "]\n";
	cout << "                                               [xxx] ***\n\n";
	s1.Insert(s1, 1);
	cout << " >>> s1.Insert(s1, 1);                 s1 = [" << s1 << "]\n";
	cout << "                                            [xxxxxx] ***\n\n";
	s2.Insert(s4, 0);
	cout << " >>> s2.Insert(s4, 0);                       s2 = [" << s2 << "]\n";
	cout << "                                                  []\n";
	s3.Insert(s2, 5);
	cout << " >>> s3.Insert(s2, 5);   s3 = [" << s3 << "]\n";
	cout << "                              [12345678901234567890]\n";

	cout << "\n--- Length -----------------------------------------\n\n";

	s1 = "xxxxxx";
	s2 = "";
	s3 = "12345678901234567890";

	cout << " s1 = [" << s1 << "]\n";
	cout << " s2 = [" << s2 << "]\n";
	cout << " s3 = [" << s3 << "]\n\n";

	cout << " >>>                               s1.Length() = [" << s1.Length() << "]\n";
	cout << "                                                 [6] ***\n\n";
	cout << " >>>                               s2.Length() = [" << s2.Length() << "]\n";
	cout << "                                                 [0] ***\n\n";
	cout << " >>>                              s3.Length() = [" << s3.Length() << "]\n";
	cout << "                                                [20] ***\n\n";

	cout << "\n--- Replace ----------------------------------------\n\n";

	s1 = "xxxxxx";
	s3 = "12345678901234567890";

	cout << " s1 = [" << s1 << "]\n";
	cout << " s3 = [" << s3 << "]\n\n";

	s3.Replace(3, 4, s1);
	cout << " >>> s3.Replace(3, 4, s1);  s3=[" << s3 << "]\n";
	cout << "                               [123xxxx8901234567890] ***\n\n";
	s3.Replace(0, 1, s1);
	cout << " >>> s3.Replace(0, 1, s1);  s3=[" << s3 << "]\n";
	cout << "                               [x23xxxx8901234567890] ***\n\n";
	s3.Replace(19, 1, s1);
	cout << " >>> s3.Replace(19, 1, s1); s3=[" << s3 << "]\n";
	cout << "                               [x23xxxx890123456789x] ***\n\n";

	cout << "\n--- SubStr ------------------------------------------\n\n";

	s1 = "xxxxxx";
	s2 = "";
	s3 = "x23xxxx890123456789x";

	cout << " s1 = [" << s1 << "]\n";
	cout << " s2 = [" << s2 << "]\n";
	cout << " s3 = [" << s3 << "]\n\n";

	s1 = s3.SubStr(0, 4);
	cout << " >>> s1 = s3.SubStr(0, 4);               s1 = [" << s1 << "]\n";
	cout << "                                              [x23x] ***\n\n";
	s2 = s3.SubStr(6, 14);
	cout << " >>> s2 = s3.SubStr(6, 14);    s2 = [" << s2 << "]\n";
	cout << "                                    [x890123456789x] ***\n\n";
	s3 = s3.SubStr(2, 6);
	cout << " >>> s3 = s3.SubStr(2, 6);             s3 = [" << s3 << "]\n";
	cout << "                                            [3xxxx8] ***\n\n";

	cout << "\n=== OPORATORS ======================================\n";

	cout << "\n--- = ----------------------------------------------\n\n";

	s1 = "x23x";
	s2 = "x890123456789x";
	s3 = "3xxxx8";

	cout << " s1 = [" << s1 << "]\n";
	cout << " s2 = [" << s2 << "]\n";
	cout << " s3 = [" << s3 << "]\n\n";

	s1 = s2;
	cout << " >>> s1 = s2;                  s1 = [" << s1 << "]\n";
	cout << "                               s1 = [x890123456789x]\n\n";
	s2 = "Howdy!";
	cout << " >>> s2 = \"Howdy!\";                    s2 = [" << s2 << "]\n";
	cout << "                                       s2 = [Howdy!]\n\n";
	s3 = s3;
	cout << " >>> s3 = s3;                          s3 = [" << s3 << "]\n";
	cout << " >>> s3 = s3;                          s3 = [3xxxx8]\n";

	cout << "\n--- + ----------------------------------------------\n\n";

	s1 = "x890123456789x";
	s2 = "Howdy!";
	s3 = "3xxxx8";	

	cout << " s1 = [" << s1 << "]\n";
	cout << " s2 = [" << s2 << "]\n";
	cout << " s3 = [" << s3 << "]\n\n";

	s1 = s1 + s2;
	cout << " >>> s1 = s1 + s2;       s1 = [" << s1 << "]\n";
	cout << "                         s1 = [x890123456789xHowdy!]\n\n";
	s2 = s2 + "Howdy!";
	cout << " >>> s2 = s2 + \"Howdy!\";         s2 = [" << s2 << "]\n";
	cout << " >>> s2 = s2 + \"Howdy!\";         s2 = [Howdy!Howdy!]\n\n";
	s3 = s3 + s3;
	cout << " >>> s3 = s3 + s3;               s3 = [" << s3 << "]\n";
	cout << " >>> s3 = s3 + s3;               s3 = [3xxxx83xxxx8]\n";

	cout << "\n--- += ---------------------------------------------\n\n";

	s1 = "x890123456789xHowdy!";
	s2 = "Howdy!Howdy!";
	s3 = "3xxxx83xxxx8";

	cout << " s1 = [" << s1 << "]\n";
	cout << " s2 = [" << s2 << "]\n";
	cout << " s3 = [" << s3 << "]\n\n";

	s1 += s2;
	cout << " >>> s1 += s2; s1=[" << s1 << "]\n";
	cout << "               s1=[x890123456789xHowdy!Howdy!Howdy!]\n\n";
	s2 += "Howdy!";
	cout << " >>> s2 += \"Howdy!\";         s2=[" << s2 << "]\n";
	cout << "                             s2=[Howdy!Howdy!Howdy!]\n\n";
	s3 += s3;
	cout << " >>> s3 += s3;         s3=[" << s3 << "]\n";
	cout << " >>> s3 += s3;         s3=[3xxxx83xxxx83xxxx83xxxx8]\n";

	cout << "\n--- [] ---------------------------------------------\n\n";

	s1 = "x890123456789xHowdy!Howdy!Howdy!";

	cout << " s1 = [" << s1 << "]\n\n";

	cout << " >>>	                                 s1[0] = [" << s1[0] << "] [x]\n";
	cout << " >>>                                     s1[3] = [" << s1[3] << "] [0]\n";
	cout << " >>>                                    s1[31] = [" << s1[31] << "] [!]\n\n";

	s1[0] = '&';
	s1[3] = '&';
	s1[31] = '&';
	cout << "s1[0] = '&';  s1[3] = '&';  s1[31] = '&';\n\n";

	cout << " >>>	                                 s1[0] = [" << s1[0] << "] [&]\n";
	cout << " >>>                                     s1[3] = [" << s1[3] << "] [&]\n";
	cout << " >>>                                    s1[31] = [" << s1[31] << "] [&]\n";

	cout << "\n--- > ----------------------------------------------\n\n";

	s1 = "&89&123456789xHowdy!Howdy!Howdy&";
	s2 = "Howdy!Howdy!Howdy!";

	cout << " s1 = [" << s1 << "]\n";
	cout << " s2 = [" << s2 << "]\n\n";

	cout << " >>>                                   s1 > s2 = [" << (s1 > s2) << "] [0]\n";
	cout << " >>>                                s1 > \"xyz\" = [" << (s1 > "xyz") << "] [0]\n";
	cout << " >>>                                   s1 > s1 = [" << (s1 > s1) << "] [0]\n";

	cout << "\n--- < ----------------------------------------------\n\n";

	s1 = "&89&123456789xHowdy!Howdy!Howdy&";
	s2 = "Howdy!Howdy!Howdy!";

	cout << " s1 = [" << s1 << "]\n";
	cout << " s2 = [" << s2 << "]\n\n";

	cout << " >>>                                   s1 < s2 = [" << (s1 < s2) << "] [1]\n";
	cout << " >>>                                s1 < \"xyz\" = [" << (s1 < "xyz") << "] [1]\n";
	cout << " >>>                                   s1 < s1 = [" << (s1 < s1) << "] [0]\n";

	cout << "\n--- >= ---------------------------------------------\n\n";

	s1 = "&89&123456789xHowdy!Howdy!Howdy&";
	s2 = "Howdy!Howdy!Howdy!";

	cout << " s1 = [" << s1 << "]\n";
	cout << " s2 = [" << s2 << "]\n\n";

	cout << " >>>                                 s1 >= s2 = [" << (s1 >= s2) << "] [0]\n";
	cout << " >>>                              s1 >= \"xyz\" = [" << (s1 >= "xyz") << "] [0]\n";
	cout << " >>>                                 s1 >= s1 = [" << (s1 >= s1) << "] [1]\n";

	cout << "\n--- <= ---------------------------------------------\n\n";

	s1 = "&89&123456789xHowdy!Howdy!Howdy&";
	s2 = "Howdy!Howdy!Howdy!";

	cout << " s1 = [" << s1 << "]\n";
	cout << " s2 = [" << s2 << "]\n\n";

	cout << " >>>                                 s1 <= s2 = [" << (s1 <= s2) << "] [1]\n";
	cout << " >>>                              s1 <= \"xyz\" = [" << (s1 <= "xyz") << "] [1]\n";
	cout << " >>>                                 s1 <= s1 = [" << (s1 <= s1) << "] [1]\n";

	cout << "\n--- == ---------------------------------------------\n\n";

	s1 = "&89&123456789xHowdy!Howdy!Howdy&";
	s2 = "Howdy!Howdy!Howdy!";

	cout << " s1 = [" << s1 << "]\n";
	cout << " s2 = [" << s2 << "]\n\n";

	cout << " >>>                                 s1 == s2 = [" << (s1 == s2) << "] [0]\n";
	cout << " >>>                              s1 == \"xyz\" = [" << (s1 == "xyz") << "] [0]\n";
	cout << " >>>                                 s1 == s1 = [" << (s1 == s1) << "] [1]\n";

	cout << "\n--- != ---------------------------------------------\n\n";

	s1 = "&89&123456789xHowdy!Howdy!Howdy&";
	s2 = "Howdy!Howdy!Howdy!";

	cout << " s1 = [" << s1 << "]\n";
	cout << " s2 = [" << s2 << "]\n\n";

	cout << " >>>                                 s1 != s2 = [" << (s1 != s2) << "] [1]\n";
	cout << " >>>                              s1 != \"xyz\" = [" << (s1 != "xyz") << "] [1]\n";
	cout << " >>>                                 s1 != s1 = [" << (s1 != s1) << "] [0]\n";

	cout << "\n--- >> ---------------------------------------------\n\n";

	cout << "\n>>> cin >> s1;\n";
	cout << " Press ENTER >";
	cin >> s1;

	cout << "                                            s1 = [" << s1 << "]\n";

	cout << "\n>>> cin >> s1;\n";
	cout << " Enter the following \"123\' >";
	cin >> s1;

	cout << "                                         s1 = [" << s1 << "]\n";

	cout << "\n>>> cin >> s1;\n";
	cout << " Enter the following \"123 456\' >";
	cin >> s1;

	cout << "                                     s1 = [" << s1 << "]\n";

	cout << "\n>>> cin >> s1;\n";
	cout << " Enter three lines of text >\n";
	cin >> s1;

	cout << "s1 = [\n" << s1 << "\n]\n";

	cout << "\nPress Enter to continue...";
	cin >> s1;
	*/

	return 0;
}


Is This A Good Question/Topic? 0
  • +

Replies To: Custom string class

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4293
  • View blog
  • Posts: 13,462
  • Joined: 25-December 09

Re: Custom string class

Posted 16 February 2011 - 07:03 PM

Quote

mt.exe : general error c101008a: Failed to save the updated manifest to the file "Debug\MyString.exe.embed.manifest". The parameter is incorrect.
1>


For this error you might try a Clean and Rebuild. If that doesn't help you might want to do a search of the error code.


Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1