求助一个list的代码,
时间:2011-12-24
来源:互联网
复制内容到剪贴板
#include <iostream>
#include <string>
#include <list>
#include <iterator>
class person
{public:
string name;
string sex;
int age;
person::person(string a, string b, int c)
{name=a;
sex=b;
age=c;
};
int main()
{list<person>first;
first.push_back(person("liuxiang","male",28));
for(list<person>::const_iterator it=first.begin();it!=first.end();it++)
{cout<<endl<<*it<<endl;
}
system("pause");}
我是想让这个代码输出liuxiang, male 28代码:
using namespace std;#include <iostream>
#include <string>
#include <list>
#include <iterator>
class person
{public:
string name;
string sex;
int age;
person::person(string a, string b, int c)
{name=a;
sex=b;
age=c;
};
int main()
{list<person>first;
first.push_back(person("liuxiang","male",28));
for(list<person>::const_iterator it=first.begin();it!=first.end();it++)
{cout<<endl<<*it<<endl;
}
system("pause");}
8 @/ l: [ ?3 K, f这几个数据,,
# L& v& U% E3 E8 W5 v! V+ ] B& {8 Q8 `; w. f" v
不知道哪有错。
作者: alleni 发布时间: 2011-12-24
复制内容到剪贴板
#include <string>
#include <list>
#include <iterator>
using namespace std;
class person
{public:
string name;
string sex;
int age;
person(string a, string b, int c)//这个可以在类内声明,而在类外定义,那么要加类限定符;如果直接在类内定义就不用加类作用符
{name=a;
sex=b;
age=c;
}
friend ostream&operator<<(ostream &out,const person &rhs)//你要输出类,那么首先要定义成员函数
{
out<<rhs.name<<"\t"<<rhs.sex<<"\t"<<rhs.age;
return out;
}
};
int main()
{list<person>first;
first.push_back(person("liuxiang","male",28));
for(list<person>::const_iterator it=first.begin();it!=first.end();it++)
{cout<<endl<<*it<<endl;
}
system("pause");}
代码:
#include <iostream>#include <string>
#include <list>
#include <iterator>
using namespace std;
class person
{public:
string name;
string sex;
int age;
person(string a, string b, int c)//这个可以在类内声明,而在类外定义,那么要加类限定符;如果直接在类内定义就不用加类作用符
{name=a;
sex=b;
age=c;
}
friend ostream&operator<<(ostream &out,const person &rhs)//你要输出类,那么首先要定义成员函数
{
out<<rhs.name<<"\t"<<rhs.sex<<"\t"<<rhs.age;
return out;
}
};
int main()
{list<person>first;
first.push_back(person("liuxiang","male",28));
for(list<person>::const_iterator it=first.begin();it!=first.end();it++)
{cout<<endl<<*it<<endl;
}
system("pause");}
作者: 月夜幻影 发布时间: 2011-12-24
复制内容到剪贴板
#include <string>
#include <list>
#include <iterator>
using namespace std;
class person
{public:
string name;
string sex;
int age;
person(string a, string b, int c);//这个可以在类内声明,而在类外定义,那么要加类限定符;如果直接在类内定义就不用加类作用符
friend ostream&operator<<(ostream &out,const person &rhs)//你要输出类,那么首先要定义成员函数
{
out<<rhs.name<<"\t"<<rhs.sex<<"\t"<<rhs.age;
return out;
}
};
person::person(string a, string b, int c)
{name=a;
sex=b;
age=c;
}
int main()
{list<person>first;
first.push_back(person("liuxiang","male",28));
for(list<person>::const_iterator it=first.begin();it!=first.end();it++)
{cout<<endl<<*it<<endl;
}
system("pause");}
代码:
#include <iostream>#include <string>
#include <list>
#include <iterator>
using namespace std;
class person
{public:
string name;
string sex;
int age;
person(string a, string b, int c);//这个可以在类内声明,而在类外定义,那么要加类限定符;如果直接在类内定义就不用加类作用符
friend ostream&operator<<(ostream &out,const person &rhs)//你要输出类,那么首先要定义成员函数
{
out<<rhs.name<<"\t"<<rhs.sex<<"\t"<<rhs.age;
return out;
}
};
person::person(string a, string b, int c)
{name=a;
sex=b;
age=c;
}
int main()
{list<person>first;
first.push_back(person("liuxiang","male",28));
for(list<person>::const_iterator it=first.begin();it!=first.end();it++)
{cout<<endl<<*it<<endl;
}
system("pause");}
作者: 月夜幻影 发布时间: 2011-12-24
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28