k so heres my problem im writing a program that has a class called String and this will take a string and remove the null charicter and it will have a varible for the length of the string.
im using Dev C++ as a compiler, yeah probly not the best but its free.
the errors im getting are when i start to overload ostream.
heres what the compiler says:
11 main.cpp In file included from main.cpp
121 My_String.h ISO C++ forbids declaration of `ostream' with no type
121 My_String.h `ostream' is neither function nor member function;
cannot be declared friend
121 My_String.h expected `;' before '&' token
125 My_String.h ISO C++ forbids declaration of `istream' with no type
125 My_String.h `istream' is neither function nor member function;
cannot be declared friend
125 My_String.h expected `;' before '&' token
G:\CISP 430\Project2\Makefile.win [Build Error] [main.o] Error 1
and now the main part of the code
first the .h file
Code:
class String
{
char* STR; //string
unsigned Len; // length of string
public
friend ostream& operator<< (ostream& , const String&);
friend istream& operator>> (istream& , const String&);
now the .cpp file
Code:
ostream& operator<<(ostream& Os, const String& s)
{
for(unsigned I=0; I < s.Len;I++)
{
Os<<s[I];
}
return (Os);
}
istream& operator>>(istream& Is, const String& s )
{
String Temp;
char cc;
while (is.get(cc))
{
if (cc=='\n')
{
break;
}
}
Temp +=cc;
s = Temp;
return Is;
}