2 回答
TA贡献1911条经验 获得超7个赞
改成友员函数,如下:
//"long_int.h"
#ifndef LONG_INT
#define LONG_INT
#include<iostream>
#include<vector>
using std::istream;
using std::ostream;
using std::vector;
class long_int
{
public:
friend istream &operator >>(istream &in,long_int &l);
friend ostream &operator <<(ostream &out,long_int &l);
private:
vector<char> longint;
};
istream& operator >>(istream &in, long_int &l)
{
char input;
in>>input;
while(input!='#')
{
if(input>='0'&&input<='9')
l.longint.push_back(input);
in>>input;
}
return in;
}
ostream & operator <<(ostream &out,long_int &l)
{
for(int i=0;i<l.longint.size();i++)
out<<l.longint[i];
return out;
}
#endif
//"main.cpp"
#include "long_int.h"
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
long_int a;
cin>>a;
cout<<endl;
cout<<a;
cout<<endl;
return 0;
}
添加回答
举报