Guys i am trying to print an array of structure but all in vain. The error i am receiving is that no suitable conversion from student to student*. Can anybody help me?
#include<iostream>
#include<string.h>
using namespace std;
struct student
{
char department[20];
char course[10];
int Roll_number;
int yearofjoining;
char name[10];
};
void print( student s[3])
{
for(int j = 0; j<3; j++)
{
cout<<"The name of the student is "<< s[j].name<<endl;
cout<<"The name of the department is "<<s[j].department<<endl;
cout<<"The name of the course is "<<s[j].course<<endl;
cout<<"The Rollnumber of the student is "<<s[j].Roll_number<<endl;
cout<<"Year of joinging is "<<s[j].yearofjoining<<endl;
}
}
void main()
{
student *s = new student[3];
for(int i = 0; i<3; i++)
{
cout<<"\nEnter Name: ";
cin.getline(s[i].name ,10);
#include<iostream>
#include<string.h>
#include<limits>//to get numeric_limits working
usingnamespace std;
struct student
{
char department[20];
char course[10];
int Roll_number;
int yearofjoining;
char name[10];
};
void print( student s[3])
{
for(int j = 0; j<3; j++)
{
cout<<"The name of the student is "<< s[j].name<<endl;
cout<<"The name of the department is "<<s[j].department<<endl;
cout<<"The name of the course is "<<s[j].course<<endl;
cout<<"The Rollnumber of the student is "<<s[j].Roll_number<<endl;
cout<<"Year of joinging is "<<s[j].yearofjoining<<endl;
}
}
int main()//void main is illegal for c++ nowdays
{
student *s = new student[3];
for(int i = 0; i<3; i++)
{
cout<<"\nEnter Name: ";
cin.getline(s[i].name ,10);
cout<<"\nEnter Department: ";
cin.getline(s[i].department, 20);
cout<<"\nEnter course: ";
cin.getline(s[i].course, 10);
cout<<"\nEnter Roll Number: ";
cin>>s[i].Roll_number;
cout<<"\nEnter Year of joining: ";
cin>>s[i].yearofjoining;
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
print(s);//no need to mention arrays when using vector
delete [] s;
system("Pause");
return 0;//main should return some stuff
}