C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 09-25-2009, 02:09 AM   #1
Registered User
 
Join Date: Sep 2009
Location: california
Posts: 7
Need some help with C++ object oriented programing

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;
}
akairyuu is offline   Reply With Quote
Old 09-25-2009, 02:57 AM   #2
Cat without Hat
 
CornedBee's Avatar
 
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   Reply With Quote
Old 09-26-2009, 02:30 AM   #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;
My_String.cpp
Code:
#include <cstdlib>
#include <iostream>
#include "My_String.h"

using namespace std;
My_String.h
Code:
#include <iostream>

using namespace std;
and if you would like to see all code just let me know
thank you.

Last edited by akairyuu; 09-26-2009 at 02:45 AM. Reason: for got code
akairyuu is offline   Reply With Quote
Reply

Tags
c++, istream, object, ostream, string

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 12:01 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22