您好,我有一个由 2 个空格分隔的 3 个 int 列表,我想阅读它们并创建一个对象。我将从数据结构、类和前/后数据中粘贴我的代码。我找不到错误的原因。欢迎任何帮助:
类.h:
class RAngle{
private:
int x,y,l,b;
int solution,prec;
RAngle(){
x = y = solution = prec = b = l = 0;
}
RAngle(int i,int j,int k){
x = i;
y = j;
l = k;
solution = 0; prec=0; b=0;
}
friend ostream& operator << (ostream& out, const RAngle& ra){
out << ra.x << " " << ra.y<<" " << ra.l <<endl;
return out;
}
friend istream& operator >>( istream& is, RAngle& ra){
is >> ra.x;
is >> ra.y;
is >> ra.l;
return is ;
}
};
数据结构.h:
template <class T>
class List
{
private:
struct Elem
{
T data;
Elem* next;
};
Elem* first;
void push_back(T data){
Elem *n = new Elem;
n->data = data;
n->next = NULL;
if (first == NULL)
{
first = n;
return ;
}
Elem *current;
for(current=first;current->next != NULL;current=current->next);
current->next = n;
}
主.cpp:
void readData(List <RAngle> &l){
*RAngle r;
int N;
ifstream f_in;
ofstream f_out;
f_in.open("ex.in",ios::in);
f_out.open("ex.out",ios::out);
f_in >> N;
for(int i=0;i<13;++i){
f_in >> r;
cout << r;
l.push_back(r);
}
f_in.close();
f_out.close();
}*
输入数据:
3 1 2
1 1 3
3 1 1
输出(阅读时打印):
1 2 1
1 3 3
1 1 3
正如你所看到的,它以第二个位置开始读取并以第一个位置结束。