![]() |
| | #1 |
| Registered User Join Date: Sep 2009 Location: california
Posts: 7
| Need some help with C++ object oriented programing 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&);
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;
}
|
| akairyuu is offline | |
| | #2 |
| Cat without Hat Join Date: Apr 2003
Posts: 8,439
| You're not including the standard headers for istream and ostream, and/or not getting them into the correct scope. What tutorial are you going by? This code has many other errors, too.
__________________ All the buzzt! CornedBee"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code." - Flon's Law |
| CornedBee is offline | |
| | #3 |
| Registered User Join Date: Sep 2009 Location: california
Posts: 7
| well thats not all my code. but just to make sure i have all the right headers in my files here they are these are just the headers in each file. Main.cpp Code: #include <cstdlib> #include <iostream> #include "My_String.h" using namespace std; Code: #include <cstdlib> #include <iostream> #include "My_String.h" using namespace std; Code: #include <iostream> using namespace std; thank you. Last edited by akairyuu; 09-26-2009 at 02:45 AM. Reason: for got code |
| akairyuu is offline | |
![]() |
| Tags |
| c++, istream, object, ostream, string |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What's a good Object Oriented Strategy for OpenGL/Graphics | indigo0086 | Game Programming | 9 | 04-03-2007 06:27 PM |
| object oriented C | FlatLost | C Programming | 4 | 11-08-2005 06:22 AM |
| Question on l-values. | Hulag | C++ Programming | 6 | 10-13-2005 04:33 PM |
| A question about constructors... | Wolve | C++ Programming | 9 | 05-04-2005 04:24 PM |