Please find out errors and correct the code please

Jan 29, 2009 at 12:40pm
HI
I have written this code but there is errors in it and not going to be compiled please help me out after removing errors.. i need on urgent bases becoz i have only one day to submit ...
this is the code
=====================
#include<iostream>
#include <string>
using std::string;

class String
{

public:

string str;
String(string s)

{
str=s;
}
void print(){

cout<<str;

}
String operator+(String obj)
{

string s1=str + obj.str;

return String(string1);
}
};

template <class myType>

myType add(myType a, myType b) {

myType res;

res = a+b;

return res;
}
int main()
{
int value1,value2;
float fvalue1,fvalue2;
string string1,string2;


cout<<"\nPlease Enter two integer values to be added";
cout<<"Please Enter First value:";
cin>>value1;
cout<<"Please Enter Second value:";
cin>>value2;
cout<<"\nEnter two Float values to be added";
cout<<"Please Enter First value:";
cin>>fvalue1;
cout<<"Please Enter Second value:";
cin>>fvalue++2;
cout<<"\nPlease Enter two Strings values to be added";
cout<<"Please Enter First String:";
cin>>string1;
cout<<"Please Enter Second value:";
cin>>string2;
cout<<"Sum of values of type int:"<<add(value1,value2)<<endl;
cout<<"Sum of values of type float:"<<add(fvalue1,fvalue2)<<endl;
String str1(string1);
String str2(string2);
String str = add(string1,string2);
cout<<"Sum of values of type String:";str.print();
cout<<endl;
system("pause");

}
Jan 29, 2009 at 12:56pm
Doesn't you're compiler return errormessages? Two hints: is string the only thin you use from the std-namespace? And check your variable names.
Jan 29, 2009 at 6:31pm
Jan 29, 2009 at 6:51pm
Additionally, you need to walk through this code very carefully and ask yourself if you are using the appropriate variables for each intended purpose.

Plus, this won't compile:
cin>>fvalue++2;

And don't forget to return 0 from main...
Topic archived. No new replies allowed.