473,799 Members | 3,229 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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=(cons t STRING &);
STRING &operator=(cons t 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==(cons t STRING &st, const STRING &st2);
friend ostream &operator<<(ost ream &os, const STRING &st);
friend istream &operator>>(ist ream *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_str ings=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::operato r=(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::operat or=(const char *s)
{
delete [] str;
len=std::strlen (s);
str=new char[len+1];
std::strcpy(str ,s);
return *this;
}
char &STRING::operat or[] (int i)
{
return str[i];
}
const char &STRING::operat or[] (int i)const
{
return str[i];
}
bool operator<(const STRING &st1, const STRING &st2)
{
return (std::strcmp(st 1.str, st2.str)<0);
}
bool operator>(const STRING &st1, const STRING &st2)
{
return st2.str<st1.str ;
}
bool operator==(cons t STRING &st1, const STRING &st2)
{
return (std::strcmp(st 1.str, st2.str)==0);
}
ostream &operator<<(ost ream &os, const STRING &st)
{
os<<st.str;
return os;
}

istream & operator>(istre am & 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<ArSiz e;i++)
{
cout<<i+1<<": ";
cin.get(temp,Ma xLen);
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()<sayin gs[shortest].length())
shortest=i;
if(sayings[i]<sayings[first])
first=i;
}
cout<<"Shortest saying:\n"<<say ings[shortest]<<endl;
cout<<"First aphabetically:\ n"<<sayings[first]<<endl;
cout<<"This program used "<<STRING::HowM any()
<<"STRING objects/Bye.\n";
return 0;
}

Jan 29 '07 #1
2 2057
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>>(ist ream *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=(cons t STRING &);
STRING &operator=(cons t 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==(cons t STRING &st, const STRING &st2);
friend ostream &operator<<(ost ream &os, const STRING &st);
friend istream &operator>>(ist ream *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_str ings=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::operato r=(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::operat or=(const char *s)
{
delete [] str;
len=std::strlen (s);
str=new char[len+1];
std::strcpy(str ,s);
return *this;
}
char &STRING::operat or[] (int i)
{
return str[i];
}
const char &STRING::operat or[] (int i)const
{
return str[i];
}
bool operator<(const STRING &st1, const STRING &st2)
{
return (std::strcmp(st 1.str, st2.str)<0);
}
bool operator>(const STRING &st1, const STRING &st2)
{
return st2.str<st1.str ;
}
bool operator==(cons t STRING &st1, const STRING &st2)
{
return (std::strcmp(st 1.str, st2.str)==0);
}
ostream &operator<<(ost ream &os, const STRING &st)
{
os<<st.str;
return os;
}

istream & operator>(istre am & 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<ArSiz e;i++)
{
cout<<i+1<<": ";
cin.get(temp,Ma xLen);
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()<sayin gs[shortest].length())
shortest=i;
if(sayings[i]<sayings[first])
first=i;
}
cout<<"Shortest saying:\n"<<say ings[shortest]<<endl;
cout<<"First aphabetically:\ n"<<sayings[first]<<endl;
cout<<"This program used "<<STRING::HowM any()
<<"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
1686
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 version but it came with the book I bought (PHP, MySQL and Apache Allin One by Julie C. Meloni pubs Sams) as I wanted a reference to point me in the right direction. After installing all three apps and starting WinMySQLAdmin 1.4 I tried to start the...
23
3292
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 to create certain textboxes, labels, and combo boxes? Any ideas would be appreciated. Thanks
8
1702
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 the lines of codes below: ------------------------------------------------ using Sem = semantics.SemanticsProcessingClass; ------------------------------------------------
7
1658
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 user in the network which has application running should automatically see the change. in case of remove action, the item should disappear from the listview.
1
1677
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 IE window (when button1 is pushed) called, "NewWin" and places the content from "comment.aspx" into it. button1.Attributes.Add("onclick", "window.open('comment.aspx','NewWin',width=550, height=450');") ....but I can't seem to get any code - java...
5
2583
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
1707
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 document using a XSL file): Function Trans()
1
1056
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 the sql server 2000. I can expore and see the server explorer in the .net environment. I dont know how to overcome with this problem. Thank you Deven Oza
2
2378
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 table login with fields username(varchar(50)), password(varchar(50)), firstname(varchar(50)), lastname(varchar(50)). U had to display username , first name, last name in default.aspx page after login. One more condition is that, if user fails login...
0
9687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10225
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9072
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7564
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.