#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib>using namespace std; #define MAXN 1002struct bign {int len,s[maxn];bign () {memset (s,0,sizeof (s)); len=1;} string str () const {String res = " "; for (int i = 0; i < len; i++) res = (char) (s[i] + ' 0 ') + res; if (res = = "") res = "0"; cout<< "String str () const\n" <<endl; return res; }/*bign operator + (const Bign & D) {bign C;} */bign operator + (const bign& b) const {bign C; C.len = 0; for (int i = 0, g = 0; G | | i < MAX (Len, B.len); i++) {int x = g; if (i < len) x + = S[i]; if (I < B.len) x + = B.s[i]; c.s[c.len++] = x% 10; g = X/10; }//cout<< "bign operator + (const bign& b) const\n" <<endl; return C; }bign operator = (const char *num) {int i;len=strlen (num); for (i=0;i<len;i++) {s[i]=num[len-1-i]-' 0 ';} return *this;}; IStream & operator >> (IStream & in,bign & x) {String S;in>>s;x=s.c_str (); return in;} ostream& operator << (ostream &out, const bign& x) {out << x.str (); cout<< "ostream& operator << (ostream &out, const bign& x) \ n" <<endl; return out;} /* Run this program using the console Pauser or add your own getch, System ("pause") or input loop */int main (int argc, Cha r** argv) {int t,k=1,z;bign a,b,c;cin >>t;z=t;while (t--) {cin>>a>>b;//Simply call your own Write function c=a+b;// Addition is to pass the left object as a reference into the overloaded operator +, where = does not use overloaded operators, only requires the system enough//cout<<c;cout << "case" <<k<< ":" << Endl;if (k!=z) cout <<a<< "+" <<b<< "=" << C << endl<<endl; else cout <<a<< "+" <<b<< "=" << c << Endl; The k=k+1;//output stream is also written by its own overloaded function}return 0;}
Today read Rujia's book, with the object-oriented overload with the operator to play a large number, he also played an article