C++怎么自定义一个输出结构体的函数

我想弄一个输出struct的函数
函数应该定义为什么类型呢。void不可以么
这是我写的程序,老是出问题。各位,见笑了,帮忙看一看
#include<iostream>
using namespace std;
void putstruct(struct)
{
cout<<struct.name<<endl;
cout<<struct.age<<endl;
}
struct album
{
string name;
int age;
}
int main()
{
album CV;
CV={"小刚",20};
putstruct(CV);
return 0;
}

可以如下定义:
template<class T>
class mix
{
public:
mix();//<>是实例化的时候才用得。
void sort_all();
void out();
private:
struct unit
{
T x;
unit *next;
}
static void del_p( unit *p);
//此处省略部分成员
};
但是出于程序可读性的考虑,还是定义在类的外边比较好,如下:
struct Student{
char number[20];
char name[20];
float math;
float english;
float history;
};
class a{
private:
struct Student stu;
}
  如果在结构体定义时,或定义后取了别名,可以用别名,否则不能省“struct”
如:typedef struct Teacher TEACHER;
则可以用TEACHER 代替struct Teacher
C语言的结构体没有存取控制权限,相当于C++存取控制权限中的public:
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2016-04-10
#include<iostream>
using namespace std;
struct album
{
string name;
int age;
};//必须打分号
void putstruct(struct album t)//结构体类型的t,“struct'可以省略
{
cout<<t.name<<endl;
cout<<t.age<<endl;
}

int main()
{
album CV={"小刚",20};
putstruct(CV);
return 0;
}本回答被提问者采纳
第2个回答  2010-08-10
结构定义少了分号,而且结构体作为参数调用时,调用错误,修改如下:

#include <iostream>

using namespace std;

struct album
{
string name;
int age;
};

void putstruct(album a)
{
cout<<a.name<<endl;
cout<<a.age<<endl;
}

int main()
{
album cv;
cv={"小光",20};
putstruct(cv);

return 0;
}