R
rhaazy
I have created this very primitive class for the purpose of performing
some simple recursive functions. I am new to C++ and the concept of
classes all together. I put this together using various resources on
the net, but am faced with an insane amount of compiler errors I don't
know what to do with. Any help would be greatly appreciated.
#include <iostream>
using namespace std;
class Cstring
{
private:
//array that will hold the strings
char array[50];
public:
//default constructor
Cstring();
//constructor that turns a single character into a string
Cstring(char&);
//constructor that creates a copy of a string
Cstring(Cstring&);
//////////////////////////////////
//overloaded operators for strings
//////////////////////////////////
//this operator adds a single character to the end of a string
friend Cstring operator + (Cstring&);
//this operator stores a copy of a string in a result string
friend Cstring operator = (Cstring&);
//these are my input/output operators
friend Cstring operator >> (Cstring&);
friend Cstring operator << (Cstring&);
//function that returns the first character of the string
char head();
//function that returns the string with the first character removed
Cstring tail();
};
char Cstring::head()
{
return array[0];
}
Cstring Cstring::tail()
{
Cstring temp;
for(int i=1; i<50; i++
{
temp.array = array;
}
return temp;
}
Cstring::Cstring()
{
for(int i=0; i<50; i++
array=' ';
}
Cstring::Cstring(char &this)
{
array[0] = this;
for (int i=1; i<50; i++
array = ' ';
}
Cstring::Cstring(Cstring &other)
{
for (int i=0; i<50; i++
array = other.array;
}
Cstring Cstring:
perator+(Cstring &left, char &right)
{
Cstring temp;
for(int i=0; i<50; i++)
temp.array = left.array;
for(i=0; i<50; i++)
{
if(temp.array==' ')
{
temp.array = right;
break
}
}
return temp;
}
Cstring:
perator=(Cstring &left, Cstring &right)
{
Cstring temp;
temp.array = right.array;
}
ostream&:
perator<<(ostream& output, Cstring &right)
{
for(int i=0; i<50; i++)
{
if(right.array != ' ')
output << right.array;
}
}
istream&:
perator>>(istream& input, Cstring &right)
{
Cstring temp;
input.getline(temp.array,50);
return temp;
}
some simple recursive functions. I am new to C++ and the concept of
classes all together. I put this together using various resources on
the net, but am faced with an insane amount of compiler errors I don't
know what to do with. Any help would be greatly appreciated.
#include <iostream>
using namespace std;
class Cstring
{
private:
//array that will hold the strings
char array[50];
public:
//default constructor
Cstring();
//constructor that turns a single character into a string
Cstring(char&);
//constructor that creates a copy of a string
Cstring(Cstring&);
//////////////////////////////////
//overloaded operators for strings
//////////////////////////////////
//this operator adds a single character to the end of a string
friend Cstring operator + (Cstring&);
//this operator stores a copy of a string in a result string
friend Cstring operator = (Cstring&);
//these are my input/output operators
friend Cstring operator >> (Cstring&);
friend Cstring operator << (Cstring&);
//function that returns the first character of the string
char head();
//function that returns the string with the first character removed
Cstring tail();
};
char Cstring::head()
{
return array[0];
}
Cstring Cstring::tail()
{
Cstring temp;
for(int i=1; i<50; i++
{
temp.array = array;
}
return temp;
}
Cstring::Cstring()
{
for(int i=0; i<50; i++
array=' ';
}
Cstring::Cstring(char &this)
{
array[0] = this;
for (int i=1; i<50; i++
array = ' ';
}
Cstring::Cstring(Cstring &other)
{
for (int i=0; i<50; i++
array = other.array;
}
Cstring Cstring:
{
Cstring temp;
for(int i=0; i<50; i++)
temp.array = left.array;
for(i=0; i<50; i++)
{
if(temp.array==' ')
{
temp.array = right;
break
}
}
return temp;
}
Cstring:
{
Cstring temp;
temp.array = right.array;
}
ostream&:
{
for(int i=0; i<50; i++)
{
if(right.array != ' ')
output << right.array;
}
}
istream&:
{
Cstring temp;
input.getline(temp.array,50);
return temp;
}