cout出错,哪位给看看?
#include<iostream>#include<vector>#include<string>usingnamespacestd;structtest{intseg...
#include<iostream>
#include<vector>
#include<string>
using namespace std;
struct test
{int seg;
int shape;
float r1,r2,l,t;
}t1;
void main()
{cout<<"段数"<<endl;
cin>>t1.seg;
cout<<"形状:1圆柱,2圆锥,3凸形,4凹形"<<endl;
cin>>t1.shape;
cout<<"r1,r2,l,t"<<endl;
cin>>t1.r1>>t1.r2>>t1.l>>t1.t;
vector<test> svec;
svec.push_back(t1);
vector<test>::iterator it=svec.begin();
vector<test>::iterator it_end=svec.end();
for(;it!=it_end;++it)
cout<<*it<<'\n';//***这里提示有错误!!!no operator"<<" matches this operands!!!
cout<<endl;
}
是怎么回事啊? 展开
#include<vector>
#include<string>
using namespace std;
struct test
{int seg;
int shape;
float r1,r2,l,t;
}t1;
void main()
{cout<<"段数"<<endl;
cin>>t1.seg;
cout<<"形状:1圆柱,2圆锥,3凸形,4凹形"<<endl;
cin>>t1.shape;
cout<<"r1,r2,l,t"<<endl;
cin>>t1.r1>>t1.r2>>t1.l>>t1.t;
vector<test> svec;
svec.push_back(t1);
vector<test>::iterator it=svec.begin();
vector<test>::iterator it_end=svec.end();
for(;it!=it_end;++it)
cout<<*it<<'\n';//***这里提示有错误!!!no operator"<<" matches this operands!!!
cout<<endl;
}
是怎么回事啊? 展开
1个回答
展开全部
你必须重载输出操作才行,结构体不能整体输出的:
#include<iostream>
#include<vector>
#include<string>
using namespace std;
struct test
{int seg;
int shape;
float r1,r2,l,t;
}t1;
ostream& operator<<(ostream &out, const struct test &t) {
out<<"shape:"<<t.shape<<";r1:"<<t.r1<<";r2:"<<t.r2<<";l:"<<t.l<<";t:"<<t.t;
return out;
}
void main()
{cout<<"段数"<<endl;
cin>>t1.seg;
cout<<"形状:1圆柱,2圆锥,3凸形,4凹形"<<endl;
cin>>t1.shape;
cout<<"r1,r2,l,t"<<endl;
cin>>t1.r1>>t1.r2>>t1.l>>t1.t;
vector<test> svec;
svec.push_back(t1);
vector<test>::iterator it=svec.begin();
vector<test>::iterator it_end=svec.end();
for(;it!=it_end;++it)
cout<<*it<<'\n';//***这里提示有错误!!!no operator"<<" matches this operands!!!
cout<<endl;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询