Richard already showed you the solution. In addition you could overload the
ostream
insertion operator (
<<
), e.g.
#include <iostream>
#include <string>
using namespace std;
struct Student
{
int age;
string sex,name,f_name,l_name,matricno,religion,bloodgroup;
};
ostream & operator << ( ostream & os, const Student & st)
{
os << st.name << "\n";
os << st.f_name << "\n";
os << st.l_name << "\n";
os << st.age << "\n";
os << st.matricno << "\n";
os << st.religion << "\n";
os << st.bloodgroup << "\n";
return os;
}
int main()
{
Student foo{ 32, "M", "Foo-Bar", "Foo", "Bar", "A12", "Foobist","A"};
cout << foo << endl;}