473,399 Members | 3,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

please help me to solve this problem, thanks. I am newcomer to C++

platform: Borland C++ 5.5 free Winxp

C++ source from: C++ primer Plus 5 Edition.

Complie Error: "operator >>" not implemented in type 'istream' for
arguments of type "STRING" in function main()
//mystring.h
#ifndef MYSTRING_H_
#define MYSTRING_H_
#include <iostream.h>

using std::ostream;
using std::istream;

class STRING
{
private:
char *str;
int len;
static int num_strings;
static const int CINLIM=80;
public:
STRING(const char *s); //constructor
STRING(); //default constructor
STRING(const STRING &);// copy constructor
~STRING();
int length()const { return len; }
//overload operator methods
STRING &operator=(const STRING &);
STRING &operator=(const char *);
char &operator[] (int i);
const char &operator[] (int i)const;
//overload operator friends
friend bool operator<(const STRING &st, const STRING &st2);
friend bool operator>(const STRING &st1, const STRING &st2);
friend bool operator==(const STRING &st, const STRING &st2);
friend ostream &operator<<(ostream &os, const STRING &st);
friend istream &operator>>(istream *is, STRING &st);
//static function
static int HowMany();
};
#endif

//mystring.cpp

#include <cstring.h>
#include <string.h>
#include "mystring.h"

using std::cin;
using std::cout;

int STRING::num_strings=0;

int STRING::HowMany()
{
return num_strings;
}
//class methods

STRING::STRING(const char *s)
{
len=std::strlen(s);
str=new char[len+1];
std::strcpy(str,s);
num_strings++;
}

STRING::STRING()
{
len=4;
str=new char[1];
str[0]='\0';
num_strings++;
}
STRING::STRING(const STRING &st)
{
num_strings++;
len=st.len;
str=new char[len+1];
std::strcpy(str,st.str);
}

STRING::~STRING()
{
--num_strings;
delete [] str;
}
//overload operator methods
//assign a STRING to a STRING
STRING & STRING::operator=(const STRING &st)
{
if(this==&st)
return *this;
delete [] str;
len=st.len;
str=new char[len+1];
std::strcpy(str, st.str);
return *this;
}
// assign a C string to a string
STRING &STRING::operator=(const char *s)
{
delete [] str;
len=std::strlen(s);
str=new char[len+1];
std::strcpy(str,s);
return *this;
}
char &STRING::operator[] (int i)
{
return str[i];
}
const char &STRING::operator[] (int i)const
{
return str[i];
}
bool operator<(const STRING &st1, const STRING &st2)
{
return (std::strcmp(st1.str, st2.str)<0);
}
bool operator>(const STRING &st1, const STRING &st2)
{
return st2.str<st1.str;
}
bool operator==(const STRING &st1, const STRING &st2)
{
return (std::strcmp(st1.str, st2.str)==0);
}
ostream &operator<<(ostream &os, const STRING &st)
{
os<<st.str;
return os;
}

istream & operator>(istream & is, STRING &st)
{
char temp[STRING::CINLIM];

is.get(temp, STRING::CINLIM);

if(is)
st=temp;
while(is && is.get()!='\n')
continue;
return is;

}
//mysaying.cpp

#include <iostream.h>
#include "mystring.h"
const int ArSize=10;
const int MaxLen=81;
int main()
{
using std::cout;
using std::cin;
using std::endl;
STRING name;
cout<<"Hi, what's your name?\n>>";
cin >name;

cout<<name<<", please enter up to "<<ArSize
<<"short sayings<empty line to quit>:\n";
STRING sayings[ArSize];
char temp[MaxLen];
int i;
for(i=0;i<ArSize;i++)
{
cout<<i+1<<": ";
cin.get(temp,MaxLen);
while(cin &&cin.get()!='\n')
continue;
if(!cin||temp[0]=='\n') //empty line
break;
else
sayings[i]=temp; //overload assignment
}
int total=i;
cout<<"Here are you sayings:\n";
for(i=0;i<total;i++)
cout<<sayings[i][0]<<": "<<sayings[i]<<endl;
int shortest=0;
int first=0;
for(i=1;i<total;i++)
{
if(sayings[i].length()<sayings[shortest].length())
shortest=i;
if(sayings[i]<sayings[first])
first=i;
}
cout<<"Shortest saying:\n"<<sayings[shortest]<<endl;
cout<<"First aphabetically:\n"<<sayings[first]<<endl;
cout<<"This program used "<<STRING::HowMany()
<<"STRING objects/Bye.\n";
return 0;
}

Jan 29 '07 #1
2 2040
Simon wrote:
platform: Borland C++ 5.5 free Winxp

C++ source from: C++ primer Plus 5 Edition.

Complie Error: "operator >>" not implemented in type 'istream' for
arguments of type "STRING" in function main()
//mystring.h
#ifndef MYSTRING_H_
#define MYSTRING_H_
#include <iostream.h>

using std::ostream;
using std::istream;
Putting 'using' in headers is no-no, it gets dragged into any file that
includes the header.
class STRING
Avoid all caps for class names, the idiomatic use for all caps is for
macros.

<snip>
friend istream &operator>>(istream *is, STRING &st);
^^
There's your problem, should be istream&.
//static function
Silly comment!
static int HowMany();
};
--
Ian Collins.
Jan 29 '07 #2
Simon wrote:
platform: Borland C++ 5.5 free Winxp

C++ source from: C++ primer Plus 5 Edition.

Complie Error: "operator >>" not implemented in type 'istream' for
arguments of type "STRING" in function main()
//mystring.h
#ifndef MYSTRING_H_
#define MYSTRING_H_
#include <iostream.h>
Non-standard include. You should use
#include <iostream>

Actually, since you never use a full iostream, just references, you
should use

#include <iosfwd>
>
using std::ostream;
using std::istream;

class STRING
{
private:
char *str;
int len;
static int num_strings;
static const int CINLIM=80;
public:
STRING(const char *s); //constructor
STRING(); //default constructor
STRING(const STRING &);// copy constructor
~STRING();
int length()const { return len; }
//overload operator methods
STRING &operator=(const STRING &);
STRING &operator=(const char *);
char &operator[] (int i);
const char &operator[] (int i)const;
//overload operator friends
friend bool operator<(const STRING &st, const STRING &st2);
friend bool operator>(const STRING &st1, const STRING &st2);
friend bool operator==(const STRING &st, const STRING &st2);
friend ostream &operator<<(ostream &os, const STRING &st);
friend istream &operator>>(istream *is, STRING &st);
//static function
static int HowMany();
};
#endif

//mystring.cpp

#include <cstring.h>
#include <string.h>
#include "mystring.h"

using std::cin;
using std::cout;

int STRING::num_strings=0;

int STRING::HowMany()
{
return num_strings;
}
//class methods

STRING::STRING(const char *s)
{
len=std::strlen(s);
str=new char[len+1];
std::strcpy(str,s);
num_strings++;
}

STRING::STRING()
{
len=4;
str=new char[1];
str[0]='\0';
num_strings++;
}
STRING::STRING(const STRING &st)
{
num_strings++;
len=st.len;
str=new char[len+1];
std::strcpy(str,st.str);
}

STRING::~STRING()
{
--num_strings;
delete [] str;
}
//overload operator methods
//assign a STRING to a STRING
STRING & STRING::operator=(const STRING &st)
{
if(this==&st)
return *this;
delete [] str;
len=st.len;
str=new char[len+1];
std::strcpy(str, st.str);
return *this;
}
// assign a C string to a string
STRING &STRING::operator=(const char *s)
{
delete [] str;
len=std::strlen(s);
str=new char[len+1];
std::strcpy(str,s);
return *this;
}
char &STRING::operator[] (int i)
{
return str[i];
}
const char &STRING::operator[] (int i)const
{
return str[i];
}
bool operator<(const STRING &st1, const STRING &st2)
{
return (std::strcmp(st1.str, st2.str)<0);
}
bool operator>(const STRING &st1, const STRING &st2)
{
return st2.str<st1.str;
}
bool operator==(const STRING &st1, const STRING &st2)
{
return (std::strcmp(st1.str, st2.str)==0);
}
ostream &operator<<(ostream &os, const STRING &st)
{
os<<st.str;
return os;
}

istream & operator>(istream & is, STRING &st)
{
char temp[STRING::CINLIM];

is.get(temp, STRING::CINLIM);

if(is)
st=temp;
while(is && is.get()!='\n')
continue;
return is;

}
//mysaying.cpp

#include <iostream.h>
#include "mystring.h"
const int ArSize=10;
const int MaxLen=81;
int main()
{
using std::cout;
using std::cin;
using std::endl;
STRING name;
cout<<"Hi, what's your name?\n>>";
cin >name;

cout<<name<<", please enter up to "<<ArSize
<<"short sayings<empty line to quit>:\n";
STRING sayings[ArSize];
char temp[MaxLen];
int i;
for(i=0;i<ArSize;i++)
{
cout<<i+1<<": ";
cin.get(temp,MaxLen);
while(cin &&cin.get()!='\n')
continue;
if(!cin||temp[0]=='\n') //empty line
break;
else
sayings[i]=temp; //overload assignment
}
int total=i;
cout<<"Here are you sayings:\n";
for(i=0;i<total;i++)
cout<<sayings[i][0]<<": "<<sayings[i]<<endl;
int shortest=0;
int first=0;
for(i=1;i<total;i++)
{
if(sayings[i].length()<sayings[shortest].length())
shortest=i;
if(sayings[i]<sayings[first])
first=i;
}
cout<<"Shortest saying:\n"<<sayings[shortest]<<endl;
cout<<"First aphabetically:\n"<<sayings[first]<<endl;
cout<<"This program used "<<STRING::HowMany()
<<"STRING objects/Bye.\n";
return 0;
}
Jan 29 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tony Wainwright | last post by:
Hi guys Have just decided to start to learn MySQL after many years in MS Access. Have got hold of MySQL 4.0.21 (Windows, as soon as I'm profiicient I'll move to Linux) - not the most recent...
23
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
8
by: Ricardo Sta. Rita | last post by:
Hello people, We have been dealing with for a long time now. It's a bit weird for a newcomer like us so we decided to ask the geniuses here. C# doesn't seem to be assigning values, consider...
7
by: Mat | last post by:
I am developping multi-user windows application. i use Access database. user edit, add and delete data from database. Request: when an item is deleted ,added or modified by an user, all others...
1
by: Jeff | last post by:
....still new to VWeb .net 2005 wtih VB... ....having some problem integrating java script to open a second browser window with my VB code. The following line (in page-load) properly opens a new...
5
by: settyv | last post by:
Hi, Below is the Javascript function that am trying to call from asp:Button control. <script language="javascript"> function ValidateDate(fromDate,toDate) { var fromDate=new Date();
1
by: shapper | last post by:
Hello, For the past hours I have been trying to solve a problem which is driving me crazy. I have to different codes where the problem to solve is the same: CODE 1 (Transforms a XML...
1
by: Deven Oza | last post by:
Hi All I am newcomer to .net world. well I tried to bind data grid using dataset to northwind database. and I am getting the following error. sqlserver does not exists, even though I installed...
2
by: itsvineeth209 | last post by:
My task is to create login control without using login control in tools. I shouldnt use sqldatasource or any other. I should use only data sets, data adapters and data readers etc. U had created...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.