A program to display data information of 5 students. This is the error message I keep getting: (error: cannot convert 'student*' to 'student**'). FYI, in passing by value , the code executes without any problem. Can you please help me this issue? Thank you!
#include<iostream>
#include<cstring>
using namespace std;
struct student
{
string name;
int roll;
int phone;
};
void display(struct student *st[5]) //Function to print information of each student
{
int i;
cout<<"Printing information of each student"<<endl;
for(i=0; i<5; i++)
{
cout<<"
Student "<<i+1<<endl;
cout<<"Name: "<<st[i]->name<<endl;
cout<<"Roll number: "<<st[i]->roll<<endl;
cout<<"Phone number: "<<st[i]->phone<<endl;
}
}
int main()
{
struct student s[5];//an array variable having 5 elements of structure student.
int i;
cout<<"Enter the information of each student"<<endl;
for(i=0; i<5; i++)
{
cout<<"Information of student "<<i+1<<endl;
cout<<"Enter name: ";
cin.ignore(); //Clears unwanted input buffer before taking the next input (string)
getline(cin,s[i].name);
cout<<"Enter roll number: ";
cin>>s[i].roll;
cout<<"Enter phone number: ";
cin>>s[i].phone;
cout<<endl; //New line after data input for each student
}
display(s); //Passing the address of the structure variable 's' as an argument to the function
return 0;
}
question from:
https://stackoverflow.com/questions/65926337/getting-an-error-while-passing-array-variable-of-a-pointer-to-structure 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…