How to use the istream and ostream?
Dear ladies and gentlemen,
I created a header file followed by a book -- C++ Primer 3rd Edition.
The header file is as the following:
//////////////////////////////////////////////////////////////////
#ifndef STRING_CLASS_H
#define STRING_CLASS_H
#include <iostream>
istream& operator>>( istream&, String& );
ostream& operator<<( ostream&, const String& );
class String;
class String {
public:
String();
String( const char* );
String( const String& );
~String();
String& operator=( const String& );
String& operator=( const char* );
bool operator==( const String& );
bool operator==( const char* );
char& operator[]( int );
int size() { return _size; }
char* c_str() { return _string; }
private:
int _size;
char *_string;
};
#endif /* STRING_CLASS_H */
/////////////////////////////////////////////////////
When I include this header file in my project and compile the project
with VC++ 7.0 which was in Visual Studio .NET 2003, the two lines would
cause error:
istream& operator>>( istream&, String& );
ostream& operator<<( ostream&, const String& );
The compiler told me that lack ";" (before the "&"). What's the problem?
How can I handle this error? Help me, please. Thank you very much.
Best regards.
Xiaoming